Fix volume, add volume command
This commit is contained in:
parent
05ef2ca95c
commit
6175762c47
80
index.js
80
index.js
|
@ -119,7 +119,6 @@ function getWFOByRoom(room) {
|
||||||
|
|
||||||
// Voice funcs
|
// Voice funcs
|
||||||
function JoinChannel(channel, track, volume, message) {
|
function JoinChannel(channel, track, volume, message) {
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
connection = dVC.joinVoiceChannel({
|
connection = dVC.joinVoiceChannel({
|
||||||
channelId: channel.id,
|
channelId: channel.id,
|
||||||
guildId: channel.guild.id,
|
guildId: channel.guild.id,
|
||||||
|
@ -142,8 +141,9 @@ function JoinChannel(channel, track, volume, message) {
|
||||||
dVC.entersState(connection, VoiceConnectionStatus.Connecting, 5_000),
|
dVC.entersState(connection, VoiceConnectionStatus.Connecting, 5_000),
|
||||||
]);
|
]);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
resolve(false);
|
message.channel.send(`Failed to reconnect to the voice channel. Stopping for now.`);
|
||||||
connection.destroy();
|
connection.destroy();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
player.on('error', error => {
|
player.on('error', error => {
|
||||||
|
@ -152,50 +152,52 @@ function JoinChannel(channel, track, volume, message) {
|
||||||
player.stop();
|
player.stop();
|
||||||
});
|
});
|
||||||
player.on(dVC.AudioPlayerStatus.Playing, () => {
|
player.on(dVC.AudioPlayerStatus.Playing, () => {
|
||||||
resolve({ status: true, message: "Playing" })
|
|
||||||
message.channel.send(`Playing stream in <#${channel.id}>`);
|
message.channel.send(`Playing stream in <#${channel.id}>`);
|
||||||
connection.paused = false;
|
connection.paused = false;
|
||||||
});
|
});
|
||||||
player.on('idle', () => {
|
player.on('idle', () => {
|
||||||
resolve({ status: true, message: "Idle" })
|
|
||||||
message.channel.send(`Stream idle.`);
|
message.channel.send(`Stream idle.`);
|
||||||
})
|
})
|
||||||
});
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function LeaveVoiceChannel(channel) {
|
function LeaveVoiceChannel(channel) {
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
// Get resource, player, etc, and destroy them
|
// Get resource, player, etc, and destroy them
|
||||||
const connection = dVC.getVoiceConnection(channel.guild.id);
|
const connection = dVC.getVoiceConnection(channel.guild.id);
|
||||||
if (connection) {
|
if (connection) {
|
||||||
connection.destroy();
|
connection.destroy();
|
||||||
return resolve(true);
|
return true
|
||||||
}
|
}
|
||||||
return resolve(false);
|
return false
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleVoicePause(channel) {
|
function toggleVoicePause(channel) {
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const connection = dVC.getVoiceConnection(channel.guild.id);
|
const connection = dVC.getVoiceConnection(channel.guild.id);
|
||||||
if (connection) {
|
if (connection) {
|
||||||
if (connection.paused) {
|
if (connection.paused) {
|
||||||
connection.player.unpause();
|
connection.player.unpause();
|
||||||
connection.paused = false;
|
connection.paused = false;
|
||||||
resolve(true);
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
connection.player.pause();
|
connection.player.pause();
|
||||||
connection.paused = true;
|
connection.paused = true;
|
||||||
resolve(true);
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
resolve(false);
|
return false;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function setVolume(channel, volume) {
|
||||||
|
const connection = dVC.getVoiceConnection(channel.guild.id);
|
||||||
|
if (connection) {
|
||||||
|
connection.player.state.resource.volume.setVolume(volume);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// func to Generate random string, ({upper, lower, number, special}, length)
|
// func to Generate random string, ({upper, lower, number, special}, length)
|
||||||
|
|
||||||
const generateRandomString = function (options, length) {
|
const generateRandomString = function (options, length) {
|
||||||
|
@ -664,6 +666,18 @@ discord.on('ready', async () => {
|
||||||
"name": "pause",
|
"name": "pause",
|
||||||
"description": "Pause/Unpause the current stream",
|
"description": "Pause/Unpause the current stream",
|
||||||
"type": 1
|
"type": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "volume",
|
||||||
|
"description": "Set the volume of the current stream",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"name": "volume",
|
||||||
|
"description": "The volume to set",
|
||||||
|
"type": 4,
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -902,13 +916,12 @@ discord.on("interactionCreate", async (interaction) => {
|
||||||
channel = interaction.member.voice.channel;
|
channel = interaction.member.voice.channel;
|
||||||
if (!channel) return interaction.reply({ content: "You need to be in a voice channel", ephemeral: true });
|
if (!channel) return interaction.reply({ content: "You need to be in a voice channel", ephemeral: true });
|
||||||
// Join the channel and play the stream
|
// Join the channel and play the stream
|
||||||
JoinChannel(channel, url, 2, interaction).then((res) => {
|
res = JoinChannel(channel, url, .1, interaction)
|
||||||
if (res.status) {
|
if (res) {
|
||||||
interaction.reply({ content: res.message, ephemeral: true });
|
interaction.reply({ content: "Playing Stream", ephemeral: true });
|
||||||
} else {
|
} else {
|
||||||
interaction.reply({ content: `Failed to play stream: ${res.message}`, ephemeral: true });
|
interaction.reply({ content: `Failed to play stream`, ephemeral: true });
|
||||||
}
|
}
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "play": // Play generic stream
|
case "play": // Play generic stream
|
||||||
|
@ -920,37 +933,48 @@ discord.on("interactionCreate", async (interaction) => {
|
||||||
channel = interaction.member.voice.channel;
|
channel = interaction.member.voice.channel;
|
||||||
if (!channel) return interaction.reply({ content: "You need to be in a voice channel", ephemeral: true });
|
if (!channel) return interaction.reply({ content: "You need to be in a voice channel", ephemeral: true });
|
||||||
// Join the channel and play the stream
|
// Join the channel and play the stream
|
||||||
JoinChannel(channel, url, 2, interaction).then((res) => {
|
st = JoinChannel(channel, url, .1, interaction)
|
||||||
if (res.status) {
|
if (st) {
|
||||||
interaction.reply({ content: res.message, ephemeral: true });
|
interaction.reply({ content: "Joined, trying to start playing.", ephemeral: true });
|
||||||
} else {
|
} else {
|
||||||
interaction.reply({ content: `Failed to play stream: ${res.message}`, ephemeral: true });
|
interaction.reply({ content: `Failed to play stream`, ephemeral: true });
|
||||||
}
|
}
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "leave": // Leave broadcastify stream
|
case "leave": // Leave broadcastify stream
|
||||||
if (!config.broadcastify.enabled) return interaction.reply({ content: "Broadcastify is not enabled", ephemeral: true });
|
if (!config.broadcastify.enabled) return interaction.reply({ content: "Broadcastify is not enabled", ephemeral: true });
|
||||||
channel = interaction.member.voice.channel;
|
channel = interaction.member.voice.channel;
|
||||||
if (!channel) return interaction.reply({ content: "You need to be in a voice channel", ephemeral: true });
|
if (!channel) return interaction.reply({ content: "You need to be in a voice channel", ephemeral: true });
|
||||||
LeaveVoiceChannel(channel).then((res) => {
|
res = LeaveVoiceChannel(channel)
|
||||||
if (res) {
|
if (res) {
|
||||||
interaction.reply({ content: "Left voice channel", ephemeral: true });
|
interaction.reply({ content: "Left voice channel", ephemeral: true });
|
||||||
} else {
|
} else {
|
||||||
interaction.reply({ content: "Failed to leave voice channel (Was i ever in one?)", ephemeral: true });
|
interaction.reply({ content: "Failed to leave voice channel (Was i ever in one?)", ephemeral: true });
|
||||||
}
|
}
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case "pause": // Pause/unpause stream
|
case "pause": // Pause/unpause stream
|
||||||
channel = interaction.member.voice.channel;
|
channel = interaction.member.voice.channel;
|
||||||
if (!channel) return interaction.reply({ content: "You need to be in a voice channel", ephemeral: true });
|
if (!channel) return interaction.reply({ content: "You need to be in a voice channel", ephemeral: true });
|
||||||
toggleVoicePause(channel).then((res) => {
|
res = toggleVoicePause(channel)
|
||||||
if (res) {
|
if (res) {
|
||||||
interaction.reply({ content: "Toggled pause", ephemeral: true });
|
interaction.reply({ content: "Toggled pause", ephemeral: true });
|
||||||
} else {
|
} else {
|
||||||
interaction.reply({ content: "Failed to toggle pause", ephemeral: true });
|
interaction.reply({ content: "Failed to toggle pause", ephemeral: true });
|
||||||
}
|
}
|
||||||
});
|
break;
|
||||||
|
case "volume": // Set volume
|
||||||
|
channel = interaction.member.voice.channel;
|
||||||
|
if (!channel) return interaction.reply({ content: "You need to be in a voice channel", ephemeral: true });
|
||||||
|
volume = interaction.options.getInteger("volume")/100;
|
||||||
|
// Make sure volume isnt negative
|
||||||
|
if (volume < 0) volume = 0;
|
||||||
|
res = setVolume(channel, volume)
|
||||||
|
if (res) {
|
||||||
|
interaction.reply({ content: `Set volume to ${volume*100}%` });
|
||||||
|
} else {
|
||||||
|
interaction.reply({ content: "Failed to set volume", ephemeral: true });
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "usersubscribe":
|
case "usersubscribe":
|
||||||
|
|
|
@ -10,6 +10,9 @@ const { join } = require('path');
|
||||||
// get user input for url and channel
|
// get user input for url and channel
|
||||||
console.log(process.argv)
|
console.log(process.argv)
|
||||||
|
|
||||||
|
channelIN = process.argv[2];
|
||||||
|
urlIN = process.argv[3];
|
||||||
|
|
||||||
client.once('ready', () => {
|
client.once('ready', () => {
|
||||||
console.log("ready");
|
console.log("ready");
|
||||||
JoinChannel(client.channels.cache.get(channelIN), urlIN);
|
JoinChannel(client.channels.cache.get(channelIN), urlIN);
|
||||||
|
@ -54,6 +57,7 @@ function JoinChannel(channel, track, volume) {
|
||||||
player.on('idle', () => {
|
player.on('idle', () => {
|
||||||
connection.destroy();
|
connection.destroy();
|
||||||
})
|
})
|
||||||
|
console.log(player.state.resource.volume.volume)
|
||||||
}
|
}
|
||||||
|
|
||||||
function LeaveVoiceChannel(channel) {
|
function LeaveVoiceChannel(channel) {
|
||||||
|
|
Loading…
Reference in a new issue