mirror of
https://github.com/keanuplayz/TravBot-v3.git
synced 2024-08-15 02:33:12 +00:00
Compare commits
No commits in common. "69a845257458221e721be42bb099a35399b8d8d7" and "8093224c4683c73549aaf76d8801b8242fcb06ba" have entirely different histories.
69a8452574
...
8093224c46
6 changed files with 833 additions and 181 deletions
925
package-lock.json
generated
925
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -21,12 +21,13 @@
|
||||||
"figlet": "^1.5.2",
|
"figlet": "^1.5.2",
|
||||||
"glob": "^7.2.0",
|
"glob": "^7.2.0",
|
||||||
"inquirer": "^8.2.0",
|
"inquirer": "^8.2.0",
|
||||||
|
"mathjs": "^9.5.1",
|
||||||
"moment": "^2.29.1",
|
"moment": "^2.29.1",
|
||||||
"ms": "^2.1.3",
|
"ms": "^2.1.3",
|
||||||
"node-wolfram-alpha": "^1.2.5",
|
|
||||||
"onion-lasers": "npm:onion-lasers-v13@^2.1.0",
|
"onion-lasers": "npm:onion-lasers-v13@^2.1.0",
|
||||||
"pet-pet-gif": "^1.0.9",
|
"pet-pet-gif": "^1.0.9",
|
||||||
"relevant-urban": "^2.0.0",
|
"relevant-urban": "^2.0.0",
|
||||||
|
"translate-google": "^1.5.0",
|
||||||
"weather-js": "^2.0.0"
|
"weather-js": "^2.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
||||||
|
|
@ -1,34 +1,24 @@
|
||||||
import {NamedCommand, RestCommand} from "onion-lasers";
|
import {NamedCommand, RestCommand} from "onion-lasers";
|
||||||
import {WolframClient} from "node-wolfram-alpha";
|
import * as math from "mathjs";
|
||||||
import {MessageEmbed} from "discord.js";
|
import {MessageEmbed} from "discord.js";
|
||||||
import {Config} from "../../structures";
|
|
||||||
|
|
||||||
export default new NamedCommand({
|
export default new NamedCommand({
|
||||||
description: "Calculates a specified math expression.",
|
description: "Calculates a specified math expression.",
|
||||||
run: "Please provide a calculation.",
|
run: "Please provide a calculation.",
|
||||||
any: new RestCommand({
|
any: new RestCommand({
|
||||||
async run({send, combined}) {
|
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;
|
let resp;
|
||||||
try {
|
try {
|
||||||
resp = await wClient.query(combined);
|
resp = math.evaluate(combined);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
return send("Something went wrong.");
|
return send("Please provide a *valid* calculation.");
|
||||||
}
|
|
||||||
|
|
||||||
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]});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
|
||||||
45
src/commands/utility/translate.ts
Normal file
45
src/commands/utility/translate.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
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`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
});
|
||||||
9
src/defs/translate.d.ts
vendored
Normal file
9
src/defs/translate.d.ts
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
interface TranslateOptions {
|
||||||
|
from?: string;
|
||||||
|
to?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module "translate-google" {
|
||||||
|
function translate(input: string, options: TranslateOptions): Promise<string>;
|
||||||
|
export = translate;
|
||||||
|
}
|
||||||
|
|
@ -14,7 +14,6 @@ class ConfigStructure extends GenericStructure {
|
||||||
public admins: string[];
|
public admins: string[];
|
||||||
public support: string[];
|
public support: string[];
|
||||||
public lavalink: boolean | null;
|
public lavalink: boolean | null;
|
||||||
public wolfram: string | null;
|
|
||||||
public systemLogsChannel: string | null;
|
public systemLogsChannel: string | null;
|
||||||
public webhooks: {[id: string]: string}; // id-token pairs
|
public webhooks: {[id: string]: string}; // id-token pairs
|
||||||
|
|
||||||
|
|
@ -26,7 +25,6 @@ class ConfigStructure extends GenericStructure {
|
||||||
this.admins = select(data.admins, [], String, true);
|
this.admins = select(data.admins, [], String, true);
|
||||||
this.support = select(data.support, [], String, true);
|
this.support = select(data.support, [], String, true);
|
||||||
this.lavalink = select(data.lavalink, null, Boolean);
|
this.lavalink = select(data.lavalink, null, Boolean);
|
||||||
this.wolfram = select(data.wolfram, null, String);
|
|
||||||
this.systemLogsChannel = select(data.systemLogsChannel, null, String);
|
this.systemLogsChannel = select(data.systemLogsChannel, null, String);
|
||||||
this.webhooks = {};
|
this.webhooks = {};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue