From a2088c53a741ee8ca36c500adf4878af60e5875d Mon Sep 17 00:00:00 2001 From: BenSegal855 Date: Thu, 25 Feb 2021 00:39:51 -0500 Subject: [PATCH 1/3] feat (wolfram): added wolfram command --- config.example.ts | 4 ++- src/commands/Productivity/wolfram.ts | 45 ++++++++++++++++++++++++++++ src/languages/en-US.ts | 23 +++++++++++++- src/lib/types/Languages.d.ts | 11 +++++++ 4 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 src/commands/Productivity/wolfram.ts diff --git a/config.example.ts b/config.example.ts index b347f33..90542f2 100644 --- a/config.example.ts +++ b/config.example.ts @@ -3,7 +3,9 @@ import { KlasaClientOptions } from 'klasa'; export const TOKENS = { BOT_TOKEN: '', // put your bot's token here - GENIUS: '' // get a genius api key and put it here (https://docs.genius.com/) + GENIUS: '', // get a genius api key and put it here (https://docs.genius.com/) + NASA: '', + WOLFRAM: '' // get an app id from https://products.wolframalpha.com/api/ }; export const CLIENT_ID = ''; // put your bot's client id here diff --git a/src/commands/Productivity/wolfram.ts b/src/commands/Productivity/wolfram.ts new file mode 100644 index 0000000..6b530d6 --- /dev/null +++ b/src/commands/Productivity/wolfram.ts @@ -0,0 +1,45 @@ +import { SteveCommand } from '@lib/structures/commands/SteveCommand'; +import { ApplyOptions } from '@skyra/decorators'; +import { CommandOptions, KlasaMessage } from 'klasa'; +import axios from 'axios'; +import { TOKENS } from '@root/config'; +import { MessageEmbed } from 'discord.js'; + +@ApplyOptions({ + aliases: ['wolfram-alpha', 'math', 'domymathhomework'], + cooldown: 30, + cooldownLevel: 'author', + description: lang => lang.tget('commandWolframDescription'), + extendedHelp: lang => lang.tget('commandWolframExtended'), + requiredPermissions: ['EMBED_LINKS'], + usage: '' +}) +export default class extends SteveCommand { + + public async run(msg: KlasaMessage, [query]: [string]) { + const loadingMsg = await msg.channel.send(msg.language.tget('commandWolframLoading')); + const url = `http://api.wolframalpha.com/v1/result?appid=${TOKENS.WOLFRAM}&i=${encodeURIComponent(query)}&units=metric`; + + axios.get(url) + .then(({ status, data: result }) => { + if (status !== 200) throw 'Bad Wolfram request'; + + const embedData = msg.language.tget('commandWolframEmbed'); + return loadingMsg.edit(new MessageEmbed() + .setTitle(embedData.title) + .setDescription(embedData.description) + .addFields([{ + name: embedData.queryHeader, + value: query + }, { + name: embedData.resultHeader, + value: result + }]) + .setFooter(embedData.footer) + .setThumbnail('https://media.discordapp.net/attachments/723241105323327581/814368531600637968/wolfram-logo.png') + .setColor('0xDD1100')); + }) + .catch(() => loadingMsg.edit(msg.language.tget('commandWolframError'))); + } + +} diff --git a/src/languages/en-US.ts b/src/languages/en-US.ts index 7026a15..00e2fec 100644 --- a/src/languages/en-US.ts +++ b/src/languages/en-US.ts @@ -107,7 +107,7 @@ export default class extends Language { prefixReminder: (prefix = `@${this.client.user!.tag}`) => `The prefix${Array.isArray(prefix) ? `es for this server are: ${prefix.map(pre => `\`${pre}\``).join(', ')}` : ` in this server is set to: \`${prefix}\`` - }`, + }`, settingGatewayExpectsGuild: 'The parameter expects either a Guild or a Guild Object.', settingGatewayValueForKeyNoext: (data, key) => `The value ${data} for the key ${key} does not exist.`, settingGatewayValueForKeyAlrext: (data, key) => `The value ${data} for the key ${key} already exists.`, @@ -773,6 +773,27 @@ export default class extends Language { extendedHelp: 'This command helps facilitate use of the Pomodoro technique; it is currently under reconstruction and thus its functions are not available. Check back soon!' }), commandPomodoroUnderConstruction: 'This command is under reconstruction and is not currently available. Check back soon!', + /** + * ################################ + * # WOLFRAM-ALPHA # + * ################################ + */ + commandWolframDescription: 'Use Wolfram Alpha to do some math.', + commandWolframExtended: builder.display('wolfram', { + examples: [ + '(3 + 9) / 7', + 'derive 4x^2 + 3x +7' + ] + }), + commandWolframLoading: 'Using mad maths skillz...', + commandWolframError: 'There was too much math and something went wrong.', + commandWolframEmbed: { + title: 'The math is done!', + description: 'Powered by [Wolfram Alpha](https://www.wolframalpha.com/).', + queryHeader: 'Your Question', + resultHeader: 'The Result', + footer: this.randomDftba + }, /** * ################################ * # SELF-ASSIGN # diff --git a/src/lib/types/Languages.d.ts b/src/lib/types/Languages.d.ts index 78c7c4a..677a0ca 100644 --- a/src/lib/types/Languages.d.ts +++ b/src/lib/types/Languages.d.ts @@ -312,6 +312,17 @@ declare module 'klasa' { commandPomodoroDescription: string; commandPomodoroExtended: string; commandPomodoroUnderConstruction: string; + commandWolframDescription: string; + commandWolframExtended: string; + commandWolframLoading: string; + commandWolframError: string; + commandWolframEmbed: { + title: string; + description: string; + queryHeader: string; + resultHeader: string; + footer: string; + }; commandAddAssignableRoleDescription: string; commandAddAssignableRoleExtended: string; commandAddAssignableRole: (addedRoles: string[]) => string; From 9aeceb484f93f6ec828d670fce54f2b203d2ecd6 Mon Sep 17 00:00:00 2001 From: BenSegal855 Date: Thu, 25 Feb 2021 00:50:02 -0500 Subject: [PATCH 2/3] Remove extra tab b/c I hit extra keys --- src/languages/en-US.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/languages/en-US.ts b/src/languages/en-US.ts index 00e2fec..f9db682 100644 --- a/src/languages/en-US.ts +++ b/src/languages/en-US.ts @@ -107,7 +107,7 @@ export default class extends Language { prefixReminder: (prefix = `@${this.client.user!.tag}`) => `The prefix${Array.isArray(prefix) ? `es for this server are: ${prefix.map(pre => `\`${pre}\``).join(', ')}` : ` in this server is set to: \`${prefix}\`` - }`, + }`, settingGatewayExpectsGuild: 'The parameter expects either a Guild or a Guild Object.', settingGatewayValueForKeyNoext: (data, key) => `The value ${data} for the key ${key} does not exist.`, settingGatewayValueForKeyAlrext: (data, key) => `The value ${data} for the key ${key} already exists.`, From edda008287728162908ed5b98bcd253e12b32199 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 25 Feb 2021 01:06:07 -0500 Subject: [PATCH 3/3] make ench happy --- src/languages/en-US.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/languages/en-US.ts b/src/languages/en-US.ts index f9db682..c49c779 100644 --- a/src/languages/en-US.ts +++ b/src/languages/en-US.ts @@ -785,7 +785,7 @@ export default class extends Language { 'derive 4x^2 + 3x +7' ] }), - commandWolframLoading: 'Using mad maths skillz...', + commandWolframLoading: 'Using mad math skillz...', commandWolframError: 'There was too much math and something went wrong.', commandWolframEmbed: { title: 'The math is done!',