Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat (wolfram): added wolfram command #66

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion config.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions src/commands/Productivity/wolfram.ts
Original file line number Diff line number Diff line change
@@ -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<CommandOptions>({
aliases: ['wolfram-alpha', 'math', 'domymathhomework'],
cooldown: 30,
cooldownLevel: 'author',
description: lang => lang.tget('commandWolframDescription'),
extendedHelp: lang => lang.tget('commandWolframExtended'),
requiredPermissions: ['EMBED_LINKS'],
usage: '<query:string>'
})
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')));
}

}
21 changes: 21 additions & 0 deletions src/languages/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 math 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 #
Expand Down
11 changes: 11 additions & 0 deletions src/lib/types/Languages.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down