diff --git a/assets/json/soundboard.json b/assets/json/soundboard.json new file mode 100644 index 00000000..0739be65 --- /dev/null +++ b/assets/json/soundboard.json @@ -0,0 +1,7 @@ +[ + "airhorn", + "cat", + "dun-dun-dun", + "pikachu", + "space" +] diff --git a/assets/sounds/airhorn.mp3 b/assets/sounds/airhorn.mp3 new file mode 100644 index 00000000..88fd671d Binary files /dev/null and b/assets/sounds/airhorn.mp3 differ diff --git a/assets/sounds/cat.mp3 b/assets/sounds/cat.mp3 new file mode 100644 index 00000000..79484ed9 Binary files /dev/null and b/assets/sounds/cat.mp3 differ diff --git a/assets/sounds/dun-dun-dun.mp3 b/assets/sounds/dun-dun-dun.mp3 new file mode 100644 index 00000000..c3037f8b Binary files /dev/null and b/assets/sounds/dun-dun-dun.mp3 differ diff --git a/assets/sounds/pikachu.mp3 b/assets/sounds/pikachu.mp3 new file mode 100644 index 00000000..8e817ceb Binary files /dev/null and b/assets/sounds/pikachu.mp3 differ diff --git a/assets/sounds/space.mp3 b/assets/sounds/space.mp3 new file mode 100644 index 00000000..0a3ad350 Binary files /dev/null and b/assets/sounds/space.mp3 differ diff --git a/commands/random/soundboard.js b/commands/random/soundboard.js new file mode 100644 index 00000000..ec636c37 --- /dev/null +++ b/commands/random/soundboard.js @@ -0,0 +1,57 @@ +const Command = require('../../structures/Command'); +const sounds = require('../../assets/json/soundboard'); +const path = require('path'); + +module.exports = class SoundboardCommand extends Command { + constructor(client) { + super(client, { + name: 'soundboard', + aliases: ['sound'], + group: 'random', + memberName: 'soundboard', + description: 'Plays a sound in your voice channel.', + details: `**Sounds:** ${sounds.join(', ')}`, + guildOnly: true, + throttling: { + usages: 1, + duration: 30 + }, + clientPermissions: ['ADD_REACTIONS'], + args: [ + { + key: 'sound', + prompt: 'What sound would you like to play?', + type: 'string', + validate: sound => { + if (sounds.includes(sound.toLowerCase())) return true; + return 'Invalid Sound. Use `help soundboard` for a list of sounds.'; + }, + parse: sound => sound.toLowerCase() + } + ] + }); + } + + async run(msg, args) { + const { sound } = args; + const channel = msg.member.voiceChannel; + if (!channel) return msg.say('Please enter a Voice Channel first.'); + if (!channel.permissionsFor(this.client.user).has(['CONNECT', 'SPEAK'])) { + return msg.say('Missing the `Connect` or `Speak` Permission for the Voice Channel.'); + } + if (!channel.joinable) return msg.say('Your Voice Channel is not joinable.'); + if (this.client.voiceConnections.has(channel.guild.id)) return msg.say('I am already playing a sound.'); + const connection = await channel.join(); + await msg.react('🔊'); + const dispatcher = connection.playFile(path.join(__dirname, '..', '..', 'assets', 'sounds', `${sound}.mp3`)); + dispatcher.once('end', () => { + channel.leave(); + msg.react('✅'); + }); + dispatcher.once('error', () => { + channel.leave(); + msg.react('⚠'); + }); + return null; + } +}; diff --git a/package.json b/package.json index c7accdb9..459afcb0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "30.1.0", + "version": "30.2.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": { @@ -39,6 +39,7 @@ "mathjs": "^3.16.1", "moment": "^2.18.1", "moment-duration-format": "^1.3.0", + "node-opus": "^0.2.6", "snekfetch": "^3.2.9", "tsubaki": "^1.2.0", "uws": "^8.14.1",