Join/Leave Voice Commands

This commit is contained in:
Dragon Fire
2020-05-05 16:42:36 -04:00
parent 799d6084ea
commit 7e1e5f37c3
9 changed files with 106 additions and 66 deletions
+8 -3
View File
@@ -132,7 +132,7 @@ in the appropriate channel's topic to use it.
## Commands
Total: 411
Total: 413
### Utility:
@@ -513,7 +513,6 @@ Total: 411
* **clap:** Sends 👏 text 👏 like 👏 this.
* **cow-say:** Makes a cow say your text.
* **cursive:** Converts text to cursive.
* **dec-talk:** The world's best Text-to-Speech.
* **dvorak:** Converts text to Dvorak encoding.
* **embed:** Sends text in an embed.
* **emojify:** Converts text to emoji form.
@@ -565,9 +564,15 @@ Total: 411
* **tax:** Determines the total cost of something plus tax.
* **units:** Converts units to/from other units.
### Other:
### Voice-Based:
* **airhorn:** Plays an airhorn sound in a voice channel.
* **dec-talk:** The world's best Text-to-Speech.
* **join:** Joins your voice channel.
* **leave:** Leaves the current voice channel.
### Other:
* **cleverbot:** Talk to Cleverbot. (Owner-Only)
* **phone-book:** Looks up phone-enabled servers.
* **phone:** Starts a phone call with a random server.
+1
View File
@@ -33,6 +33,7 @@ client.registry
['edit-meme', 'Meme Generators'],
['edit-text', 'Text Manipulation'],
['edit-number', 'Number Manipulation'],
['voice', 'Voice-Based'],
['other', 'Other'],
['roleplay', 'Roleplay'],
['readme', 'README Generators']
-49
View File
@@ -1,49 +0,0 @@
const Command = require('../../structures/Command');
const path = require('path');
const sounds = require('../../assets/json/airhorn');
module.exports = class AirhornCommand extends Command {
constructor(client) {
super(client, {
name: 'airhorn',
group: 'other',
memberName: 'airhorn',
description: 'Plays an airhorn sound in a voice channel.',
guildOnly: true,
throttling: {
usages: 1,
duration: 10
},
credit: [
{
name: 'Discord',
url: 'https://discord.com/',
reason: 'Airhorn Sounds',
reasonURL: 'https://github.com/discord/airhornbot/tree/master/audio'
}
]
});
}
async run(msg) {
const voiceChannel = msg.member.voice.channel;
if (!voiceChannel) return msg.say('Please enter a voice channel first.');
if (!voiceChannel.permissionsFor(this.client.user).has(['CONNECT', 'SPEAK'])) {
return msg.say('Missing the "Connect" or "Speak" permission for the voice channel.');
}
if (!voiceChannel.joinable) return msg.say('Your voice channel is not joinable.');
if (this.client.voice.connections.has(voiceChannel.guild.id)) return msg.say('I am already playing a sound.');
try {
const connection = await voiceChannel.join();
const airhorn = sounds[Math.floor(Math.random() * sounds.length)];
const dispatcher = connection.play(path.join(__dirname, '..', '..', 'assets', 'sounds', 'airhorn', airhorn));
await msg.react('🔉');
dispatcher.once('finish', () => voiceChannel.leave());
dispatcher.once('error', () => voiceChannel.leave());
return null;
} catch (err) {
voiceChannel.leave();
throw err;
}
}
};
-1
View File
@@ -6,7 +6,6 @@ module.exports = class InviteCommand extends Command {
constructor(client) {
super(client, {
name: 'invite',
aliases: ['join'],
group: 'util',
memberName: 'invite',
description: 'Responds with the bot\'s invite links.',
+41
View File
@@ -0,0 +1,41 @@
const Command = require('../../structures/Command');
const path = require('path');
const sounds = require('../../assets/json/airhorn');
module.exports = class AirhornCommand extends Command {
constructor(client) {
super(client, {
name: 'airhorn',
group: 'voice',
memberName: 'airhorn',
description: 'Plays an airhorn sound in a voice channel.',
guildOnly: true,
throttling: {
usages: 1,
duration: 10
},
userPermissions: ['CONNECT', 'SPEAK'],
clientPermissions: ['ADD_REACTIONS', 'READ_MESSAGE_HISTORY'],
credit: [
{
name: 'Discord',
url: 'https://discord.com/',
reason: 'Airhorn Sounds',
reasonURL: 'https://github.com/discord/airhornbot/tree/master/audio'
}
]
});
}
async run(msg) {
const inGuild = msg.guild ? undefined : null;
const connection = this.client.voice.connections.get(msg.guild.id);
if (!connection) {
return msg.say(`I am not in a voice channel. Use ${msg.anyUsage('join', inGuild, inGuild)} to fix that!.`);
}
const airhorn = sounds[Math.floor(Math.random() * sounds.length)];
connection.play(path.join(__dirname, '..', '..', 'assets', 'sounds', 'airhorn', airhorn));
await msg.react('🔉');
return null;
}
};
@@ -6,7 +6,7 @@ module.exports = class DECTalkCommand extends Command {
super(client, {
name: 'dec-talk',
aliases: ['text-to-speech', 'tts'],
group: 'edit-text',
group: 'voice',
memberName: 'dec-talk',
description: 'The world\'s best Text-to-Speech.',
guildOnly: true,
@@ -47,25 +47,19 @@ module.exports = class DECTalkCommand extends Command {
}
async run(msg, { text }) {
const voiceChannel = msg.member.voice.channel;
if (!voiceChannel) return msg.say('Please enter a voice channel first.');
if (!voiceChannel.permissionsFor(this.client.user).has(['CONNECT', 'SPEAK'])) {
return msg.say('Missing the "Connect" or "Speak" permission for the voice channel.');
const inGuild = msg.guild ? undefined : null;
const connection = this.client.voice.connections.get(msg.guild.id);
if (!connection) {
return msg.say(`I am not in a voice channel. Use ${msg.anyUsage('join', inGuild, inGuild)} to fix that!.`);
}
if (!voiceChannel.joinable) return msg.say('Your voice channel is not joinable.');
if (this.client.voice.connections.has(voiceChannel.guild.id)) return msg.say('I am already playing a sound.');
try {
const connection = await voiceChannel.join();
const { url } = await request
.get('http://tts.cyzon.us/tts')
.query({ text });
const dispatcher = connection.play(url);
connection.play(url);
await msg.react('🔉');
dispatcher.once('finish', () => voiceChannel.leave());
dispatcher.once('error', () => voiceChannel.leave());
return null;
} catch (err) {
voiceChannel.leave();
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
+27
View File
@@ -0,0 +1,27 @@
const Command = require('../../structures/Command');
module.exports = class JoinCommand extends Command {
constructor(client) {
super(client, {
name: 'join',
aliases: ['join-voice-channel', 'join-vc', 'join-voice', 'join-channel'],
group: 'voice',
memberName: 'join',
description: 'Joins your voice channel.',
guarded: true,
userPermissions: ['CONNECT']
});
}
async run(msg) {
const voiceChannel = msg.member.voice.channel;
if (!voiceChannel) return msg.say('Please enter a voice channel first.');
if (!voiceChannel.permissionsFor(this.client.user).has(['CONNECT', 'SPEAK', 'VIEW_CHANNEL'])) {
return msg.say('I am missing the "Connect", "Speak", or "View Channel" permission for this voice channel.');
}
if (!voiceChannel.joinable) return msg.say('Your voice channel is not joinable.');
if (this.client.voice.connections.has(voiceChannel.guild.id)) return msg.say('I am already in a voice channel.');
await voiceChannel.join();
return msg.reply(`Joined **${voiceChannel.name}**!`);
}
};
+22
View File
@@ -0,0 +1,22 @@
const Command = require('../../structures/Command');
module.exports = class LeaveCommand extends Command {
constructor(client) {
super(client, {
name: 'leave',
aliases: ['leave-voice-channel', 'leave-vc', 'leave-voice', 'leave-channel'],
group: 'voice',
memberName: 'leave',
description: 'Leaves the current voice channel.',
guarded: true,
userPermissions: ['MOVE_MEMBERS']
});
}
run(msg) {
const connection = this.client.voice.connections.get(msg.guild.id);
if (!connection) return msg.say('I am not in a voice channel.');
connection.channel.leave();
return msg.reply(`Left **${connection.channel.name}**...`);
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "114.4.0",
"version": "114.5.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {