diff --git a/commands/games/gunfight.js b/commands/games/gunfight.js index 520c0065..44819e6b 100644 --- a/commands/games/gunfight.js +++ b/commands/games/gunfight.js @@ -1,4 +1,5 @@ const Command = require('../../structures/Command'); +const { wait } = require('../../structures/Util'); const words = ['fire', 'draw', 'shoot', 'bang', 'pull']; module.exports = class GunfightCommand extends Command { @@ -40,19 +41,17 @@ module.exports = class GunfightCommand extends Command { } await msg.say('Get Ready...'); const length = Math.floor(Math.random() * ((30000 - 1000) + 1)) + 1000; - this.client.setTimeout(async () => { - const word = words[Math.floor(Math.random() * words.length)]; - await msg.say(`TYPE \`${word.toUpperCase()}\` NOW!`); - const filter = res => [opponent.id, msg.author.id].includes(res.author.id) && res.content.toLowerCase() === word; // eslint-disable-line max-len - const winner = await msg.channel.awaitMessages(filter, { - max: 1, - time: 30000 - }); - this.fighting.delete(msg.guild.id); - if (!winner.size) return msg.say('Oh... No one won.'); - return msg.say(`And the winner is ${winner.first().author.username}!`); - }, length); - return null; + await wait(length); + const word = words[Math.floor(Math.random() * words.length)]; + await msg.say(`TYPE \`${word.toUpperCase()}\` NOW!`); + const filter = res => [opponent.id, msg.author.id].includes(res.author.id) && res.content.toLowerCase() === word; + const winner = await msg.channel.awaitMessages(filter, { + max: 1, + time: 30000 + }); + this.fighting.delete(msg.guild.id); + if (!winner.size) return msg.say('Oh... No one won.'); + return msg.say(`And the winner is ${winner.first().author.username}!`); } catch (err) { this.fighting.delete(msg.guild.id); return msg.say(`Oh no, an Error occurred: \`${err.message}\`. Try again later!`); diff --git a/commands/random-img/gelbooru.js b/commands/random-img/gelbooru.js index b47ba172..3b0d5928 100644 --- a/commands/random-img/gelbooru.js +++ b/commands/random-img/gelbooru.js @@ -1,8 +1,8 @@ const Command = require('../../structures/Command'); const { stripIndents } = require('common-tags'); const snekfetch = require('snekfetch'); -const { promisifyAll } = require('tsubaki'); -const xml = promisifyAll(require('xml2js')); +const { promisify } = require('util'); +const xml = promisify(require('xml2js').parseString); module.exports = class GelbooruCommand extends Command { constructor(client) { @@ -34,7 +34,7 @@ module.exports = class GelbooruCommand extends Command { tags: query, limit: 200 }); - const { posts } = await xml.parseStringAsync(text); + const { posts } = await xml(text); if (posts.$.count === '0') return msg.say('No Results.'); return msg.say(stripIndents` ${query ? `Result for ${query}:` : 'Random Image:'} diff --git a/commands/random-img/rule34.js b/commands/random-img/rule34.js index 90abbe54..3c0c36eb 100644 --- a/commands/random-img/rule34.js +++ b/commands/random-img/rule34.js @@ -1,8 +1,8 @@ const Command = require('../../structures/Command'); const { stripIndents } = require('common-tags'); const snekfetch = require('snekfetch'); -const { promisifyAll } = require('tsubaki'); -const xml = promisifyAll(require('xml2js')); +const { promisify } = require('util'); +const xml = promisify(require('xml2js').parseString); module.exports = class Rule34Command extends Command { constructor(client) { @@ -34,7 +34,7 @@ module.exports = class Rule34Command extends Command { tags: query, limit: 200 }); - const { posts } = await xml.parseStringAsync(text); + const { posts } = await xml(text); if (posts.$.count === '0') return msg.say('No Results.'); return msg.say(stripIndents` ${query ? `Result for ${query}:` : 'Random Image:'} diff --git a/commands/random-img/safebooru.js b/commands/random-img/safebooru.js index 0355913c..f1ea54e4 100644 --- a/commands/random-img/safebooru.js +++ b/commands/random-img/safebooru.js @@ -1,8 +1,8 @@ const Command = require('../../structures/Command'); const { stripIndents } = require('common-tags'); const snekfetch = require('snekfetch'); -const { promisifyAll } = require('tsubaki'); -const xml = promisifyAll(require('xml2js')); +const { promisify } = require('util'); +const xml = promisify(require('xml2js').parseString); module.exports = class SafebooruCommand extends Command { constructor(client) { @@ -34,7 +34,7 @@ module.exports = class SafebooruCommand extends Command { tags: query, limit: 200 }); - const { posts } = await xml.parseStringAsync(text); + const { posts } = await xml(text); if (posts.$.count === '0') return msg.say('No Results.'); return msg.say(stripIndents` ${query ? `Result for ${query}:` : 'Random Image:'} diff --git a/commands/search/anime.js b/commands/search/anime.js index a2771afd..9165f737 100644 --- a/commands/search/anime.js +++ b/commands/search/anime.js @@ -2,8 +2,8 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); const { cleanXML } = require('../../structures/Util'); -const { promisifyAll } = require('tsubaki'); -const xml = promisifyAll(require('xml2js')); +const { promisify } = require('util'); +const xml = promisify(require('xml2js').parseString); const { ANIMELIST_LOGIN } = process.env; module.exports = class AnimeCommand extends Command { @@ -30,7 +30,7 @@ module.exports = class AnimeCommand extends Command { const { text } = await snekfetch .get(`https://${ANIMELIST_LOGIN}@myanimelist.net/api/anime/search.xml`) .query({ q: query }); - const { anime } = await xml.parseStringAsync(text); + const { anime } = await xml(text); const synopsis = cleanXML(anime.entry[0].synopsis[0].substr(0, 2048)); const embed = new MessageEmbed() .setColor(0x2D54A2) diff --git a/commands/search/manga.js b/commands/search/manga.js index 8a86fa8d..2e43e6ea 100644 --- a/commands/search/manga.js +++ b/commands/search/manga.js @@ -2,8 +2,8 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const snekfetch = require('snekfetch'); const { cleanXML } = require('../../structures/Util'); -const { promisifyAll } = require('tsubaki'); -const xml = promisifyAll(require('xml2js')); +const { promisify } = require('util'); +const xml = promisify(require('xml2js').parseString); const { ANIMELIST_LOGIN } = process.env; module.exports = class MangaCommand extends Command { @@ -30,7 +30,7 @@ module.exports = class MangaCommand extends Command { const { text } = await snekfetch .get(`https://${ANIMELIST_LOGIN}@myanimelist.net/api/manga/search.xml`) .query({ q: query }); - const { manga } = await xml.parseStringAsync(text); + const { manga } = await xml(text); const synopsis = cleanXML(manga.entry[0].synopsis[0].substr(0, 2048)); const embed = new MessageEmbed() .setColor(0x2D54A2) diff --git a/package.json b/package.json index 459afcb0..381268d1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "30.2.0", + "version": "30.2.1", "description": "Your personal server companion.", "main": "Shard.js", "scripts": { @@ -41,7 +41,6 @@ "moment-duration-format": "^1.3.0", "node-opus": "^0.2.6", "snekfetch": "^3.2.9", - "tsubaki": "^1.2.0", "uws": "^8.14.1", "xml2js": "^0.4.17", "zalgolize": "^1.2.4" diff --git a/structures/Util.js b/structures/Util.js index 85059a01..2dfb6f58 100644 --- a/structures/Util.js +++ b/structures/Util.js @@ -1,4 +1,5 @@ const snekfetch = require('snekfetch'); +const { promisify } = require('util'); const { CARBON_KEY, DBOTS_KEY, DBOTSORG_KEY } = process.env; class Util { @@ -56,6 +57,10 @@ class Util { const word = `<${setting}>`; return parsed.slice(word.length, parsed.length - (word.length + 1)); } + + static wait(time) { + return promisify(setTimeout)(time); + } } module.exports = Util;