From 68bed9552ce35ac55a0afb9d5883882281a6c0cb Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Tue, 14 Nov 2017 21:48:04 +0000 Subject: [PATCH] stuff --- commands/number-edit/math.js | 30 ------------------- commands/other/gender-guess.js | 13 +++----- commands/search/reverse-dictionary.js | 43 --------------------------- package.json | 1 - 4 files changed, 4 insertions(+), 83 deletions(-) delete mode 100644 commands/number-edit/math.js delete mode 100644 commands/search/reverse-dictionary.js diff --git a/commands/number-edit/math.js b/commands/number-edit/math.js deleted file mode 100644 index e073cb31..00000000 --- a/commands/number-edit/math.js +++ /dev/null @@ -1,30 +0,0 @@ -const { Command } = require('discord.js-commando'); -const math = require('mathjs'); - -module.exports = class MathCommand extends Command { - constructor(client) { - super(client, { - name: 'math', - aliases: ['calculator', 'calc'], - group: 'number-edit', - memberName: 'math', - description: 'Evaluates a math expression.', - args: [ - { - key: 'expression', - prompt: 'What expression would you like to evaluate?', - type: 'string' - } - ] - }); - } - - run(msg, { expression }) { - try { - const answer = math.eval(expression).toString(); - return msg.say(answer).catch(() => msg.reply('Invalid expression.')); - } catch (err) { - return msg.reply('Invalid expression.'); - } - } -}; diff --git a/commands/other/gender-guess.js b/commands/other/gender-guess.js index 9369bdb7..e9bf8171 100644 --- a/commands/other/gender-guess.js +++ b/commands/other/gender-guess.js @@ -1,6 +1,5 @@ const { Command } = require('discord.js-commando'); const snekfetch = require('snekfetch'); -const { MASHAPE_KEY } = process.env; module.exports = class GenderGuessCommand extends Command { constructor(client) { @@ -16,7 +15,7 @@ module.exports = class GenderGuessCommand extends Command { prompt: 'What name do you want to determine the gender of?', type: 'string', max: 1950, - parse: name => name.toLowerCase() + parse: name => encodeURIComponent(name) } ] }); @@ -24,13 +23,9 @@ module.exports = class GenderGuessCommand extends Command { async run(msg, { name }) { try { - const { body } = await snekfetch - .get('https://udayogra-find-gender-by-name-v1.p.mashape.com/analysis') - .query({ firstname: name }) - .set({ 'X-Mashape-Key': MASHAPE_KEY }); - if (!body.male || !body.female) return msg.say(`I have no idea what gender ${body.name} is.`); - const gender = body.male > body.female ? 'male' : 'female'; - return msg.say(`I'm ${body[gender]}% sure ${body.name} is a ${gender} name.`); + const { body } = await snekfetch.get(`https://api.namsor.com/onomastics/api/json/gender/${name}/null`); + if (body.gender === 'unknown') return msg.say(`I have no idea what gender ${body.firstName} is.`); + return msg.say(`I'm ${Math.abs(body.scale * 100)}% sure ${body.firstName} is a ${body.gender} name.`); } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/search/reverse-dictionary.js b/commands/search/reverse-dictionary.js deleted file mode 100644 index aa8da39e..00000000 --- a/commands/search/reverse-dictionary.js +++ /dev/null @@ -1,43 +0,0 @@ -const { Command } = require('discord.js-commando'); -const snekfetch = require('snekfetch'); -const { stripIndents } = require('common-tags'); -const { WORDNIK_KEY } = process.env; - -module.exports = class ReverseDictionaryCommand extends Command { - constructor(client) { - super(client, { - name: 'reverse-dictionary', - aliases: ['reverse-define', 'wordnik-reverse-define', 'wordnik-reverse-dictionary'], - group: 'search', - memberName: 'reverse-dictionary', - description: 'Responds with the closest word for a given definition.', - args: [ - { - key: 'definition', - prompt: 'What definition would you like to look up?', - type: 'string' - } - ] - }); - } - - async run(msg, { definition }) { - try { - const { body } = await snekfetch - .get('http://api.wordnik.com/v4/words.json/reverseDictionary') - .query({ - query: definition, - limit: 1, - api_key: WORDNIK_KEY - }); - if (!body.results) return msg.say('Could not find any results.'); - const data = body.results[0]; - return msg.say(stripIndents` - **${data.word}** - ${data.text} - `); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } - } -}; diff --git a/package.json b/package.json index 370b9272..1c81df8f 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,6 @@ "discord.js": "github:hydrabolt/discord.js", "discord.js-commando": "github:gawdl3y/discord.js-commando", "erlpack": "github:discordapp/erlpack", - "mathjs": "^3.16.5", "node-opus": "^0.2.7", "snekfetch": "^3.5.8", "uws": "^8.14.1",