diff --git a/assets/json/xiao-fact.json b/assets/json/xiao-fact.json index 109094da..f937f524 100644 --- a/assets/json/xiao-fact.json +++ b/assets/json/xiao-fact.json @@ -65,5 +65,6 @@ "To this day, no one has actually tried to date Dragon Fire after using the `dating` command. Several irl friends thought the joke was funny, though.", "The `screenshot` command uses a massive 2,000,000 entry array to check for adult sites. Some _still_ fall through the cracks.", "The `ship` command will call you a narcissist if you test yourself with yourself.", - "Whenever Dragon Fire gets a real fortune cookie, he adds the fortune to the `fortune` command." + "Whenever Dragon Fire gets a real fortune cookie, he adds the fortune to the `fortune` command.", + "The `whos-that-pokemon` command will play a sound effect if both you and the bot are in a voice channel when the command is used.", ] diff --git a/assets/sounds/whos-that-pokemon.mp3 b/assets/sounds/whos-that-pokemon.mp3 new file mode 100644 index 00000000..a0cc5423 Binary files /dev/null and b/assets/sounds/whos-that-pokemon.mp3 differ diff --git a/commands/games-sp/whos-that-pokemon.js b/commands/games-sp/whos-that-pokemon.js index 41d5ea6e..95216c16 100644 --- a/commands/games-sp/whos-that-pokemon.js +++ b/commands/games-sp/whos-that-pokemon.js @@ -1,6 +1,8 @@ const Command = require('../../structures/Command'); const { createCanvas, loadImage, registerFont } = require('canvas'); const request = require('node-superfetch'); +const { Readable } = require('stream'); +const { reactIfAble } = require('../../util/Util'); const { silhouette } = require('../../util/Canvas'); const path = require('path'); registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Pokemon Solid.ttf'), { family: 'Pokemon' }); @@ -68,11 +70,24 @@ module.exports = class WhosThatPokemonCommand extends Command { const names = data.names.map(name => name.name.toLowerCase()); const attachment = await this.createImage(data, true); const answerAttachment = await this.createImage(data, false); + const connection = msg.guild ? this.client.voice.connections.get(msg.guild.id) : null; + if (connection) { + connection.play(path.join(__dirname, '..', '..', 'assets', 'sounds', 'whos-that-pokemon.mp3')); + await reactIfAble(msg, this.client.user, '๐Ÿ”‰'); + } await msg.reply('**You have 15 seconds, who\'s that Pokรฉmon?**', { files: [attachment] }); const msgs = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, { max: 1, time: 15000 }); + if (connection) { + connection.dispatcher.end(); + await data.fetchCry(); + if (data.cry) { + connection.play(Readable.from([data.cry])); + await reactIfAble(msg, this.client.user, '๐Ÿ”‰'); + } + } if (!msgs.size) return msg.reply(`Time! It's **${data.name}**!`, { files: [answerAttachment] }); const guess = msgs.first().content.toLowerCase(); const slug = this.client.pokemon.makeSlug(guess); diff --git a/commands/search/pokedex.js b/commands/search/pokedex.js index 19926f9e..697219a4 100644 --- a/commands/search/pokedex.js +++ b/commands/search/pokedex.js @@ -1,6 +1,8 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); +const { Readable } = require('stream'); +const { reactIfAble } = require('../../util/Util'); module.exports = class PokedexCommand extends Command { constructor(client) { @@ -69,6 +71,14 @@ module.exports = class PokedexCommand extends Command { if (found.id === data.id) return `**${found.name}**`; return found.name; }).join(' -> ')); + const connection = msg.guild ? this.client.voice.connections.get(msg.guild.id) : null; + if (connection) { + await data.fetchCry(); + if (data.cry) { + connection.play(Readable.from([data.cry])); + await reactIfAble(msg, this.client.user, '๐Ÿ”‰'); + } + } return msg.embed(embed); } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); diff --git a/package.json b/package.json index dd18cd37..538ce652 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "119.34.8", + "version": "119.34.9", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/structures/pokemon/Pokemon.js b/structures/pokemon/Pokemon.js index a1ace237..e676c335 100644 --- a/structures/pokemon/Pokemon.js +++ b/structures/pokemon/Pokemon.js @@ -37,6 +37,7 @@ module.exports = class Pokemon { }; this.typesCached = data.missingno || false; this.missingno = data.missingno || false; + this.cry = null; } get displayID() { @@ -108,4 +109,15 @@ module.exports = class Pokemon { } return this.chain.data; } + + async fetchCry() { + if (this.cry) return this.cry; + try { + const { body } = await request.get(`https://pokemoncries.com/cries/${this.id}.mp3`); + this.cry = body; + return this.cry; + } catch { + return null; + } + } };