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
|
||||
function JoinChannel(channel, track, volume, message) {
|
||||
return new Promise((resolve, reject) => {
|
||||
connection = dVC.joinVoiceChannel({
|
||||
channelId: channel.id,
|
||||
guildId: channel.guild.id,
|
||||
|
@ -142,8 +141,9 @@ function JoinChannel(channel, track, volume, message) {
|
|||
dVC.entersState(connection, VoiceConnectionStatus.Connecting, 5_000),
|
||||
]);
|
||||
} catch (error) {
|
||||
resolve(false);
|
||||
message.channel.send(`Failed to reconnect to the voice channel. Stopping for now.`);
|
||||
connection.destroy();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
player.on('error', error => {
|
||||
|
@ -152,50 +152,52 @@ function JoinChannel(channel, track, volume, message) {
|
|||
player.stop();
|
||||
});
|
||||
player.on(dVC.AudioPlayerStatus.Playing, () => {
|
||||
resolve({ status: true, message: "Playing" })
|
||||
message.channel.send(`Playing stream in <#${channel.id}>`);
|
||||
connection.paused = false;
|
||||
});
|
||||
player.on('idle', () => {
|
||||
resolve({ status: true, message: "Idle" })
|
||||
message.channel.send(`Stream idle.`);
|
||||
})
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
function LeaveVoiceChannel(channel) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// Get resource, player, etc, and destroy them
|
||||
const connection = dVC.getVoiceConnection(channel.guild.id);
|
||||
if (connection) {
|
||||
connection.destroy();
|
||||
return resolve(true);
|
||||
return true
|
||||
}
|
||||
return resolve(false);
|
||||
});
|
||||
return false
|
||||
}
|
||||
|
||||
function toggleVoicePause(channel) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const connection = dVC.getVoiceConnection(channel.guild.id);
|
||||
if (connection) {
|
||||
if (connection.paused) {
|
||||
connection.player.unpause();
|
||||
connection.paused = false;
|
||||
resolve(true);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
connection.player.pause();
|
||||
connection.paused = true;
|
||||
resolve(true);
|
||||
return true
|
||||
}
|
||||
}
|
||||
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)
|
||||
|
||||
const generateRandomString = function (options, length) {
|
||||
|
@ -664,6 +666,18 @@ discord.on('ready', async () => {
|
|||
"name": "pause",
|
||||
"description": "Pause/Unpause the current stream",
|
||||
"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;
|
||||
if (!channel) return interaction.reply({ content: "You need to be in a voice channel", ephemeral: true });
|
||||
// Join the channel and play the stream
|
||||
JoinChannel(channel, url, 2, interaction).then((res) => {
|
||||
if (res.status) {
|
||||
interaction.reply({ content: res.message, ephemeral: true });
|
||||
res = JoinChannel(channel, url, .1, interaction)
|
||||
if (res) {
|
||||
interaction.reply({ content: "Playing Stream", ephemeral: true });
|
||||
} else {
|
||||
interaction.reply({ content: `Failed to play stream: ${res.message}`, ephemeral: true });
|
||||
interaction.reply({ content: `Failed to play stream`, ephemeral: true });
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case "play": // Play generic stream
|
||||
|
@ -920,37 +933,48 @@ discord.on("interactionCreate", async (interaction) => {
|
|||
channel = interaction.member.voice.channel;
|
||||
if (!channel) return interaction.reply({ content: "You need to be in a voice channel", ephemeral: true });
|
||||
// Join the channel and play the stream
|
||||
JoinChannel(channel, url, 2, interaction).then((res) => {
|
||||
if (res.status) {
|
||||
interaction.reply({ content: res.message, ephemeral: true });
|
||||
st = JoinChannel(channel, url, .1, interaction)
|
||||
if (st) {
|
||||
interaction.reply({ content: "Joined, trying to start playing.", ephemeral: true });
|
||||
} else {
|
||||
interaction.reply({ content: `Failed to play stream: ${res.message}`, ephemeral: true });
|
||||
interaction.reply({ content: `Failed to play stream`, ephemeral: true });
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case "leave": // Leave broadcastify stream
|
||||
if (!config.broadcastify.enabled) return interaction.reply({ content: "Broadcastify is not enabled", ephemeral: true });
|
||||
channel = interaction.member.voice.channel;
|
||||
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) {
|
||||
interaction.reply({ content: "Left voice channel", ephemeral: true });
|
||||
} else {
|
||||
interaction.reply({ content: "Failed to leave voice channel (Was i ever in one?)", ephemeral: true });
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
case "pause": // Pause/unpause stream
|
||||
channel = interaction.member.voice.channel;
|
||||
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) {
|
||||
interaction.reply({ content: "Toggled pause", ephemeral: true });
|
||||
} else {
|
||||
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;
|
||||
|
||||
case "usersubscribe":
|
||||
|
|
|
@ -10,6 +10,9 @@ const { join } = require('path');
|
|||
// get user input for url and channel
|
||||
console.log(process.argv)
|
||||
|
||||
channelIN = process.argv[2];
|
||||
urlIN = process.argv[3];
|
||||
|
||||
client.once('ready', () => {
|
||||
console.log("ready");
|
||||
JoinChannel(client.channels.cache.get(channelIN), urlIN);
|
||||
|
@ -54,6 +57,7 @@ function JoinChannel(channel, track, volume) {
|
|||
player.on('idle', () => {
|
||||
connection.destroy();
|
||||
})
|
||||
console.log(player.state.resource.volume.volume)
|
||||
}
|
||||
|
||||
function LeaveVoiceChannel(channel) {
|
||||
|
|
Loading…
Reference in a new issue