diff options
author | AnInternetTroll <lucafulger@gmail.com> | 2021-09-14 19:33:15 +0000 |
---|---|---|
committer | AnInternetTroll <lucafulger@gmail.com> | 2021-09-14 19:33:15 +0000 |
commit | f51d7ecb96cd420f9137f02e520b8a2cfeb520c8 (patch) | |
tree | 0561720219972c8bd37f2d21907bc30383f45ced | |
parent | 68a475d2317dd6a04c1596c59bf83df8b7f1ff73 (diff) | |
download | speedrunbot-slash-f51d7ecb96cd420f9137f02e520b8a2cfeb520c8.tar speedrunbot-slash-f51d7ecb96cd420f9137f02e520b8a2cfeb520c8.tar.gz speedrunbot-slash-f51d7ecb96cd420f9137f02e520b8a2cfeb520c8.tar.bz2 speedrunbot-slash-f51d7ecb96cd420f9137f02e520b8a2cfeb520c8.tar.lz speedrunbot-slash-f51d7ecb96cd420f9137f02e520b8a2cfeb520c8.tar.xz speedrunbot-slash-f51d7ecb96cd420f9137f02e520b8a2cfeb520c8.tar.zst speedrunbot-slash-f51d7ecb96cd420f9137f02e520b8a2cfeb520c8.zip |
Add discord start
-rw-r--r-- | .gitignore | 1 | ||||
-rwxr-xr-x | src/client.ts | 53 | ||||
-rw-r--r-- | src/deploy.ts | 21 | ||||
-rw-r--r-- | src/srcom/slashCommands.ts | 51 |
4 files changed, 126 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env
\ No newline at end of file diff --git a/src/client.ts b/src/client.ts new file mode 100755 index 0000000..cff55ed --- /dev/null +++ b/src/client.ts @@ -0,0 +1,53 @@ +#!/usr/bin/env -S deno run --allow-net=www.speedrun.com,gateway.discord.gg,discord.com --allow-env --allow-read=. --no-check +import { + ApplicationCommandInteraction, + Client, + Embed, + event, + Intents, + slash, +} from "https://deno.land/x/harmony@v2.1.3/mod.ts"; +import { commands } from "./srcom/slashCommands.ts"; + +import "https://deno.land/x/dot_env@0.2.0/load.ts"; + +import { games } from "./srcom/games.ts"; + +export class SpeedRunBot extends Client { + @event() + ready() { + console.log("Started!"); + this.register(); + } + + register() { + commands.forEach((command) => { + this.interactions.commands.create(command, Deno.env.get("TEST_SERVER")) + .then((cmd) => console.log(`Created Slash Command ${cmd.name}!`)) + .catch((cmd) => + console.log(`Failed to create ${Deno.inspect(cmd)} command!`) + ); + }); + } + + @slash() + async games(i: ApplicationCommandInteraction) { + const [username] = i.options.map((opt) => opt.value); + const [title, ...content] = + (await games(username, { outputType: "markdown" })).split("\n"); + + const embed = new Embed({ + title: title, + description: content.join("\n"), + }); + await i.reply({ embeds: [embed] }); + } +} + +if (import.meta.main) { + const client = new SpeedRunBot({ + intents: Intents.None, + token: Deno.env.get("TOKEN"), + }); + client.connect(); +} diff --git a/src/deploy.ts b/src/deploy.ts new file mode 100644 index 0000000..eddd408 --- /dev/null +++ b/src/deploy.ts @@ -0,0 +1,21 @@ +import { + Embed, + handle, + init, +} from "https://deno.land/x/harmony@v2.1.3/deploy.ts"; +import { games } from "./srcom/games.ts"; + +init({ env: true }); + +handle("games", async (i) => { + const [username] = i.options.map((opt) => opt.value); + const [title, ...content] = + (await games(username, { outputType: "markdown" })).split("\n"); + + const embed = new Embed({ + title: title, + description: content.join("\n"), + }); + + i.send(embed); +}); diff --git a/src/srcom/slashCommands.ts b/src/srcom/slashCommands.ts new file mode 100644 index 0000000..656cf17 --- /dev/null +++ b/src/srcom/slashCommands.ts @@ -0,0 +1,51 @@ +import { + SlashCommandOptionType, + SlashCommandPartial, +} from "https://deno.land/x/harmony@v2.1.3/deploy.ts"; +const srcUser = { + name: "username", + type: SlashCommandOptionType.STRING, + description: "A speedrun.com username", +}; +const srcGame = { + name: "game", + description: "A game abbreviation.", + type: SlashCommandOptionType.STRING, +}; +export const commands: SlashCommandPartial[] = [ + { + name: "games", + description: "See how many games a player has submitted runs to.", + options: [ + { + ...srcUser, + required: true, + }, + ], + }, + { + name: "categories", + description: "See the categories of a game.", + options: [ + { + ...srcGame, + required: true, + }, + ], + }, + { + name: "examined", + description: "See how many runs a user has examined.", + options: [ + { + ...srcUser, + required: true, + }, + srcGame, + { + ...srcGame, + name: "game2", + }, + ], + }, +]; |