Remove tsubaki, better wait in gunfight

This commit is contained in:
Daniel Odendahl Jr
2017-08-15 13:16:39 +00:00
parent b4f0f8d0c1
commit 7cbdab46b1
8 changed files with 33 additions and 30 deletions
+12 -13
View File
@@ -1,4 +1,5 @@
const Command = require('../../structures/Command'); const Command = require('../../structures/Command');
const { wait } = require('../../structures/Util');
const words = ['fire', 'draw', 'shoot', 'bang', 'pull']; const words = ['fire', 'draw', 'shoot', 'bang', 'pull'];
module.exports = class GunfightCommand extends Command { module.exports = class GunfightCommand extends Command {
@@ -40,19 +41,17 @@ module.exports = class GunfightCommand extends Command {
} }
await msg.say('Get Ready...'); await msg.say('Get Ready...');
const length = Math.floor(Math.random() * ((30000 - 1000) + 1)) + 1000; const length = Math.floor(Math.random() * ((30000 - 1000) + 1)) + 1000;
this.client.setTimeout(async () => { await wait(length);
const word = words[Math.floor(Math.random() * words.length)]; const word = words[Math.floor(Math.random() * words.length)];
await msg.say(`TYPE \`${word.toUpperCase()}\` NOW!`); 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 filter = res => [opponent.id, msg.author.id].includes(res.author.id) && res.content.toLowerCase() === word;
const winner = await msg.channel.awaitMessages(filter, { const winner = await msg.channel.awaitMessages(filter, {
max: 1, max: 1,
time: 30000 time: 30000
}); });
this.fighting.delete(msg.guild.id); this.fighting.delete(msg.guild.id);
if (!winner.size) return msg.say('Oh... No one won.'); if (!winner.size) return msg.say('Oh... No one won.');
return msg.say(`And the winner is ${winner.first().author.username}!`); return msg.say(`And the winner is ${winner.first().author.username}!`);
}, length);
return null;
} catch (err) { } catch (err) {
this.fighting.delete(msg.guild.id); this.fighting.delete(msg.guild.id);
return msg.say(`Oh no, an Error occurred: \`${err.message}\`. Try again later!`); return msg.say(`Oh no, an Error occurred: \`${err.message}\`. Try again later!`);
+3 -3
View File
@@ -1,8 +1,8 @@
const Command = require('../../structures/Command'); const Command = require('../../structures/Command');
const { stripIndents } = require('common-tags'); const { stripIndents } = require('common-tags');
const snekfetch = require('snekfetch'); const snekfetch = require('snekfetch');
const { promisifyAll } = require('tsubaki'); const { promisify } = require('util');
const xml = promisifyAll(require('xml2js')); const xml = promisify(require('xml2js').parseString);
module.exports = class GelbooruCommand extends Command { module.exports = class GelbooruCommand extends Command {
constructor(client) { constructor(client) {
@@ -34,7 +34,7 @@ module.exports = class GelbooruCommand extends Command {
tags: query, tags: query,
limit: 200 limit: 200
}); });
const { posts } = await xml.parseStringAsync(text); const { posts } = await xml(text);
if (posts.$.count === '0') return msg.say('No Results.'); if (posts.$.count === '0') return msg.say('No Results.');
return msg.say(stripIndents` return msg.say(stripIndents`
${query ? `Result for ${query}:` : 'Random Image:'} ${query ? `Result for ${query}:` : 'Random Image:'}
+3 -3
View File
@@ -1,8 +1,8 @@
const Command = require('../../structures/Command'); const Command = require('../../structures/Command');
const { stripIndents } = require('common-tags'); const { stripIndents } = require('common-tags');
const snekfetch = require('snekfetch'); const snekfetch = require('snekfetch');
const { promisifyAll } = require('tsubaki'); const { promisify } = require('util');
const xml = promisifyAll(require('xml2js')); const xml = promisify(require('xml2js').parseString);
module.exports = class Rule34Command extends Command { module.exports = class Rule34Command extends Command {
constructor(client) { constructor(client) {
@@ -34,7 +34,7 @@ module.exports = class Rule34Command extends Command {
tags: query, tags: query,
limit: 200 limit: 200
}); });
const { posts } = await xml.parseStringAsync(text); const { posts } = await xml(text);
if (posts.$.count === '0') return msg.say('No Results.'); if (posts.$.count === '0') return msg.say('No Results.');
return msg.say(stripIndents` return msg.say(stripIndents`
${query ? `Result for ${query}:` : 'Random Image:'} ${query ? `Result for ${query}:` : 'Random Image:'}
+3 -3
View File
@@ -1,8 +1,8 @@
const Command = require('../../structures/Command'); const Command = require('../../structures/Command');
const { stripIndents } = require('common-tags'); const { stripIndents } = require('common-tags');
const snekfetch = require('snekfetch'); const snekfetch = require('snekfetch');
const { promisifyAll } = require('tsubaki'); const { promisify } = require('util');
const xml = promisifyAll(require('xml2js')); const xml = promisify(require('xml2js').parseString);
module.exports = class SafebooruCommand extends Command { module.exports = class SafebooruCommand extends Command {
constructor(client) { constructor(client) {
@@ -34,7 +34,7 @@ module.exports = class SafebooruCommand extends Command {
tags: query, tags: query,
limit: 200 limit: 200
}); });
const { posts } = await xml.parseStringAsync(text); const { posts } = await xml(text);
if (posts.$.count === '0') return msg.say('No Results.'); if (posts.$.count === '0') return msg.say('No Results.');
return msg.say(stripIndents` return msg.say(stripIndents`
${query ? `Result for ${query}:` : 'Random Image:'} ${query ? `Result for ${query}:` : 'Random Image:'}
+3 -3
View File
@@ -2,8 +2,8 @@ const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js'); const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch'); const snekfetch = require('snekfetch');
const { cleanXML } = require('../../structures/Util'); const { cleanXML } = require('../../structures/Util');
const { promisifyAll } = require('tsubaki'); const { promisify } = require('util');
const xml = promisifyAll(require('xml2js')); const xml = promisify(require('xml2js').parseString);
const { ANIMELIST_LOGIN } = process.env; const { ANIMELIST_LOGIN } = process.env;
module.exports = class AnimeCommand extends Command { module.exports = class AnimeCommand extends Command {
@@ -30,7 +30,7 @@ module.exports = class AnimeCommand extends Command {
const { text } = await snekfetch const { text } = await snekfetch
.get(`https://${ANIMELIST_LOGIN}@myanimelist.net/api/anime/search.xml`) .get(`https://${ANIMELIST_LOGIN}@myanimelist.net/api/anime/search.xml`)
.query({ q: query }); .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 synopsis = cleanXML(anime.entry[0].synopsis[0].substr(0, 2048));
const embed = new MessageEmbed() const embed = new MessageEmbed()
.setColor(0x2D54A2) .setColor(0x2D54A2)
+3 -3
View File
@@ -2,8 +2,8 @@ const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js'); const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch'); const snekfetch = require('snekfetch');
const { cleanXML } = require('../../structures/Util'); const { cleanXML } = require('../../structures/Util');
const { promisifyAll } = require('tsubaki'); const { promisify } = require('util');
const xml = promisifyAll(require('xml2js')); const xml = promisify(require('xml2js').parseString);
const { ANIMELIST_LOGIN } = process.env; const { ANIMELIST_LOGIN } = process.env;
module.exports = class MangaCommand extends Command { module.exports = class MangaCommand extends Command {
@@ -30,7 +30,7 @@ module.exports = class MangaCommand extends Command {
const { text } = await snekfetch const { text } = await snekfetch
.get(`https://${ANIMELIST_LOGIN}@myanimelist.net/api/manga/search.xml`) .get(`https://${ANIMELIST_LOGIN}@myanimelist.net/api/manga/search.xml`)
.query({ q: query }); .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 synopsis = cleanXML(manga.entry[0].synopsis[0].substr(0, 2048));
const embed = new MessageEmbed() const embed = new MessageEmbed()
.setColor(0x2D54A2) .setColor(0x2D54A2)
+1 -2
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiaobot", "name": "xiaobot",
"version": "30.2.0", "version": "30.2.1",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "Shard.js", "main": "Shard.js",
"scripts": { "scripts": {
@@ -41,7 +41,6 @@
"moment-duration-format": "^1.3.0", "moment-duration-format": "^1.3.0",
"node-opus": "^0.2.6", "node-opus": "^0.2.6",
"snekfetch": "^3.2.9", "snekfetch": "^3.2.9",
"tsubaki": "^1.2.0",
"uws": "^8.14.1", "uws": "^8.14.1",
"xml2js": "^0.4.17", "xml2js": "^0.4.17",
"zalgolize": "^1.2.4" "zalgolize": "^1.2.4"
+5
View File
@@ -1,4 +1,5 @@
const snekfetch = require('snekfetch'); const snekfetch = require('snekfetch');
const { promisify } = require('util');
const { CARBON_KEY, DBOTS_KEY, DBOTSORG_KEY } = process.env; const { CARBON_KEY, DBOTS_KEY, DBOTSORG_KEY } = process.env;
class Util { class Util {
@@ -56,6 +57,10 @@ class Util {
const word = `<${setting}>`; const word = `<${setting}>`;
return parsed.slice(word.length, parsed.length - (word.length + 1)); return parsed.slice(word.length, parsed.length - (word.length + 1));
} }
static wait(time) {
return promisify(setTimeout)(time);
}
} }
module.exports = Util; module.exports = Util;