Compare commits

...

2 Commits

Author SHA1 Message Date
Alyxia Sother 69a8452574
R.I.P. .translate, may you return another day 2021-11-03 13:52:39 +01:00
Alyxia Sother 78f3490003
Fixed .calc by moving to WolframAlpha API 2021-11-03 13:45:58 +01:00
6 changed files with 181 additions and 833 deletions

925
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -21,13 +21,12 @@
"figlet": "^1.5.2",
"glob": "^7.2.0",
"inquirer": "^8.2.0",
"mathjs": "^9.5.1",
"moment": "^2.29.1",
"ms": "^2.1.3",
"node-wolfram-alpha": "^1.2.5",
"onion-lasers": "npm:onion-lasers-v13@^2.1.0",
"pet-pet-gif": "^1.0.9",
"relevant-urban": "^2.0.0",
"translate-google": "^1.5.0",
"weather-js": "^2.0.0"
},
"devDependencies": {

View File

@ -1,24 +1,34 @@
import {NamedCommand, RestCommand} from "onion-lasers";
import * as math from "mathjs";
import {WolframClient} from "node-wolfram-alpha";
import {MessageEmbed} from "discord.js";
import {Config} from "../../structures";
export default new NamedCommand({
description: "Calculates a specified math expression.",
run: "Please provide a calculation.",
any: new RestCommand({
async run({send, combined}) {
if (Config.wolfram === null) return send("There's no Wolfram token in the config.");
const wClient = new WolframClient(Config.wolfram);
let resp;
try {
resp = math.evaluate(combined);
} catch (e) {
return send("Please provide a *valid* calculation.");
resp = await wClient.query(combined);
} catch (e: any) {
return send("Something went wrong.");
}
if (!resp.data.queryresult.pods) return send("No pods were returned. Your query was likely invalid.");
else {
// TODO: Please don't hardcode the pod to fetch, try to figure out
// which is the right one based on some comparisons instead
const embed = new MessageEmbed()
.setColor(0xffffff)
.setTitle("Math Calculation")
.addField("Input", `\`\`\`\n${combined}\`\`\``)
.addField("Output", `\`\`\`\n${resp.data.queryresult.pods[1].subpods[0].plaintext}\`\`\``);
return send({embeds: [embed]});
}
const embed = new MessageEmbed()
.setColor(0xffffff)
.setTitle("Math Calculation")
.addField("Input", `\`\`\`js\n${combined}\`\`\``)
.addField("Output", `\`\`\`js\n${resp}\`\`\``);
return send({embeds: [embed]});
}
})
});

View File

@ -1,45 +0,0 @@
import {Command, NamedCommand, RestCommand} from "onion-lasers";
import translate from "translate-google";
export default new NamedCommand({
description: "Translates your input.",
usage: "<lang ID> <input>",
run: "You need to specify a language to translate to.",
any: new Command({
run: "You need to enter some text to translate.",
any: new RestCommand({
async run({send, args}) {
const lang = args[0];
const input = args.slice(1).join(" ");
translate(input, {
to: lang
})
.then((res) => {
send({
embeds: [
{
title: "Translation",
fields: [
{
name: "Input",
value: `\`\`\`${input}\`\`\``
},
{
name: "Output",
value: `\`\`\`${res}\`\`\``
}
]
}
]
});
})
.catch((error) => {
console.error("[translate]", error);
send(
`${error}\nPlease use the following list: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes`
);
});
}
})
})
});

View File

@ -1,9 +0,0 @@
interface TranslateOptions {
from?: string;
to?: string;
}
declare module "translate-google" {
function translate(input: string, options: TranslateOptions): Promise<string>;
export = translate;
}

View File

@ -14,6 +14,7 @@ class ConfigStructure extends GenericStructure {
public admins: string[];
public support: string[];
public lavalink: boolean | null;
public wolfram: string | null;
public systemLogsChannel: string | null;
public webhooks: {[id: string]: string}; // id-token pairs
@ -25,6 +26,7 @@ class ConfigStructure extends GenericStructure {
this.admins = select(data.admins, [], String, true);
this.support = select(data.support, [], String, true);
this.lavalink = select(data.lavalink, null, Boolean);
this.wolfram = select(data.wolfram, null, String);
this.systemLogsChannel = select(data.systemLogsChannel, null, String);
this.webhooks = {};