mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Better voice management
This commit is contained in:
@@ -34,8 +34,6 @@ module.exports = class PlayCommand extends Command {
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
this.dispatchers = new Map();
|
||||
}
|
||||
|
||||
async run(msg, { query }) {
|
||||
@@ -44,15 +42,15 @@ module.exports = class PlayCommand extends Command {
|
||||
const usage = this.client.registry.commands.get('join').usage();
|
||||
return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`);
|
||||
}
|
||||
if (this.dispatchers.has(msg.guild.id)) return msg.reply('I am already playing music in this server.');
|
||||
if (this.client.dispatchers.has(msg.guild.id)) return msg.reply('I am already playing audio in this server.');
|
||||
const result = await this.searchForVideo(query, msg.channel.nsfw || false);
|
||||
if (!result) return msg.say('Could not find any results for your query.');
|
||||
const canPlay = await this.canUseVideo(result, msg.channel.nsfw || false);
|
||||
if (!canPlay) return msg.say('I cannot play this video.');
|
||||
const dispatcher = connection.play(ytdl(result, { filter: 'audioonly', quality: 'lowest' }));
|
||||
this.dispatchers.set(msg.guild.id, dispatcher);
|
||||
dispatcher.once('finish', () => this.dispatchers.delete(msg.guild.id));
|
||||
dispatcher.once('error', () => this.dispatchers.delete(msg.guild.id));
|
||||
this.client.dispatchers.set(msg.guild.id, dispatcher);
|
||||
dispatcher.once('finish', () => this.client.dispatchers.delete(msg.guild.id));
|
||||
dispatcher.once('error', () => this.client.dispatchers.delete(msg.guild.id));
|
||||
await reactIfAble(msg, this.client.user, '🔉');
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,10 @@ module.exports = class LeaveCommand extends Command {
|
||||
if (!msg.channel.permissionsFor(msg.author).has('MOVE_MEMBERS') && connection.channel.members.size > 2) {
|
||||
return msg.reply('You need the "Move members" permission to remove me from this voice channel.');
|
||||
}
|
||||
if (this.client.dispatchers.has(msg.guild.id)) {
|
||||
const usage = this.client.registry.commands.get('stop').usage();
|
||||
return msg.reply(`I am currently playing audio in this server. Please use ${usage} first.`);
|
||||
}
|
||||
connection.channel.leave();
|
||||
return msg.reply(`Left **${connection.channel.name}**...`);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
const Command = require('../../structures/Command');
|
||||
|
||||
module.exports = class StopCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'stop',
|
||||
aliases: ['stop-voice-channel', 'stop-vc', 'stop-voice', 'stop-play', 'stop-playing'],
|
||||
group: 'util-public',
|
||||
memberName: 'stop',
|
||||
description: 'Stops the current audio playing.',
|
||||
guildOnly: true,
|
||||
guarded: true
|
||||
});
|
||||
}
|
||||
|
||||
run(msg) {
|
||||
const connection = this.client.voice.connections.get(msg.guild.id);
|
||||
if (!connection) return msg.reply('I am not in a voice channel.');
|
||||
if (!msg.channel.permissionsFor(msg.author).has('MOVE_MEMBERS') && connection.channel.members.size > 2) {
|
||||
return msg.reply('You need the "Move members" permission to stop playing audio.');
|
||||
}
|
||||
if (!this.client.dispatchers.has(msg.guild.id)) {
|
||||
return msg.reply(`I am not currently playing audio in this server.`);
|
||||
}
|
||||
this.client.dispatchers.get(msg.guild.id).end();
|
||||
return msg.reply('Stopped playing.');
|
||||
}
|
||||
};
|
||||
@@ -34,8 +34,12 @@ module.exports = class AirhornCommand extends Command {
|
||||
const usage = this.client.registry.commands.get('join').usage();
|
||||
return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`);
|
||||
}
|
||||
if (this.client.dispatchers.has(msg.guild.id)) return msg.reply('I am already playing audio in this server.');
|
||||
const airhorn = sounds[Math.floor(Math.random() * sounds.length)];
|
||||
connection.play(path.join(__dirname, '..', '..', 'assets', 'sounds', 'airhorn', airhorn));
|
||||
const dispatcher = connection.play(path.join(__dirname, '..', '..', 'assets', 'sounds', 'airhorn', airhorn));
|
||||
this.client.dispatchers.set(msg.guild.id, dispatcher);
|
||||
dispatcher.once('finish', () => this.client.dispatchers.delete(msg.guild.id));
|
||||
dispatcher.once('error', () => this.client.dispatchers.delete(msg.guild.id));
|
||||
await reactIfAble(msg, this.client.user, '🔉');
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -54,12 +54,16 @@ module.exports = class DECTalkCommand extends Command {
|
||||
const usage = this.client.registry.commands.get('join').usage();
|
||||
return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`);
|
||||
}
|
||||
if (this.client.dispatchers.has(msg.guild.id)) return msg.reply('I am already playing audio in this server.');
|
||||
try {
|
||||
await reactIfAble(msg, this.client.user, LOADING_EMOJI_ID, '💬');
|
||||
const { body } = await request
|
||||
.get('http://tts.cyzon.us/tts')
|
||||
.query({ text });
|
||||
connection.play(Readable.from([body]));
|
||||
const dispatcher = connection.play(Readable.from([body]));
|
||||
this.client.dispatchers.set(msg.guild.id, dispatcher);
|
||||
dispatcher.once('finish', () => this.client.dispatchers.delete(msg.guild.id));
|
||||
dispatcher.once('error', () => this.client.dispatchers.delete(msg.guild.id));
|
||||
await reactIfAble(msg, this.client.user, '🔉');
|
||||
return null;
|
||||
} catch (err) {
|
||||
|
||||
@@ -128,7 +128,11 @@ module.exports = class SoundboardCommand extends Command {
|
||||
const usage = this.client.registry.commands.get('join').usage();
|
||||
return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`);
|
||||
}
|
||||
connection.play(path.join(__dirname, '..', '..', 'assets', 'sounds', ...sound));
|
||||
if (this.client.dispatchers.has(msg.guild.id)) return msg.reply('I am already playing audio in this server.');
|
||||
const dispatcher = connection.play(path.join(__dirname, '..', '..', 'assets', 'sounds', ...sound));
|
||||
this.client.dispatchers.set(msg.guild.id, dispatcher);
|
||||
dispatcher.once('finish', () => this.client.dispatchers.delete(msg.guild.id));
|
||||
dispatcher.once('error', () => this.client.dispatchers.delete(msg.guild.id));
|
||||
await reactIfAble(msg, this.client.user, '🔉');
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ module.exports = class VocodesCommand extends Command {
|
||||
const usage = this.client.registry.commands.get('join').usage();
|
||||
return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`);
|
||||
}
|
||||
if (this.client.dispatchers.has(msg.guild.id)) return msg.reply('I am already playing audio in this server.');
|
||||
try {
|
||||
await reactIfAble(msg, this.client.user, LOADING_EMOJI_ID, '💬');
|
||||
const { body } = await request
|
||||
@@ -59,7 +60,10 @@ module.exports = class VocodesCommand extends Command {
|
||||
speaker: voice,
|
||||
text
|
||||
});
|
||||
connection.play(Readable.from([Buffer.from(body.audio_base64, 'base64')]));
|
||||
const dispatcher = connection.play(Readable.from([Buffer.from(body.audio_base64, 'base64')]));
|
||||
this.client.dispatchers.set(msg.guild.id, dispatcher);
|
||||
dispatcher.once('finish', () => this.client.dispatchers.delete(msg.guild.id));
|
||||
dispatcher.once('error', () => this.client.dispatchers.delete(msg.guild.id));
|
||||
await reactIfAble(msg, this.client.user, '🔉');
|
||||
return null;
|
||||
} catch (err) {
|
||||
|
||||
@@ -43,6 +43,7 @@ module.exports = class XiaoClient extends CommandoClient {
|
||||
disableMentions: 'everyone'
|
||||
}) : null;
|
||||
this.games = new Collection();
|
||||
this.dispatchers = new Map();
|
||||
this.phone = new Collection();
|
||||
this.activities = activities;
|
||||
this.leaveMessages = leaveMsgs;
|
||||
|
||||
Reference in New Issue
Block a user