diff --git a/discord-bot/commands/index.ts b/discord-bot/commands/index.ts new file mode 100644 index 000000000..2322d17a8 --- /dev/null +++ b/discord-bot/commands/index.ts @@ -0,0 +1,5 @@ +import { questionCommand } from "./q"; + +export const commands = [questionCommand]; + +export const commandsMap = Object.fromEntries(commands.map((c) => [c.name, c])); diff --git a/discord-bot/commands/q.ts b/discord-bot/commands/q.ts new file mode 100644 index 000000000..cc399be8a --- /dev/null +++ b/discord-bot/commands/q.ts @@ -0,0 +1,130 @@ +import type { BotCommand } from "../types"; +import ids from "../ids"; +import { SlashCommandBuilder } from "@discordjs/builders"; + +const groupedLinks = { + sg: { + seeking: [ + "https://cdn.discordapp.com/attachments/865925063731445760/865925984065552404/SG_NT_Seeking.png", + "https://cdn.discordapp.com/attachments/865925063731445760/865926005776056360/SG_HT_Seeking.png", + ], + grillers: [ + "https://cdn.discordapp.com/attachments/951441475034558484/951441708745388062/SG_NT_Grillers.png", + "https://cdn.discordapp.com/attachments/951441475034558484/951441742283018291/SG_HT_Grillers.png", + ], + rush: [ + "https://cdn.discordapp.com/attachments/951442362775765022/951442493927485450/SG_NT_Rush.png", + "https://cdn.discordapp.com/attachments/951442362775765022/951442573971578880/SG_HT_Rush.png", + ], + }, + mb: { + seeking: [ + "https://cdn.discordapp.com/attachments/865925063731445760/865926250963140628/MB_NT_Seeking.png", + "https://cdn.discordapp.com/attachments/865925063731445760/865926264409030696/MB_HT_Seeking.png", + ], + grillers: [ + "https://cdn.discordapp.com/attachments/951441475034558484/951441787573141534/MB_NT_Grillers.png", + "https://cdn.discordapp.com/attachments/951441475034558484/951441828299817020/MB_HT_Grillers.png", + ], + rush: [ + "https://cdn.discordapp.com/attachments/951442362775765022/951442753563291688/MB_NT_Rush.png", + "https://cdn.discordapp.com/attachments/951442362775765022/951442772345356288/MB_HT_Rush.png", + ], + }, + lo: { + seeking: [ + "https://cdn.discordapp.com/attachments/865925063731445760/865926336199655424/LO_NT_Seeking.png", + "https://cdn.discordapp.com/attachments/865925063731445760/865926346545954836/LO_HT_Seeking.png", + ], + grillers: [ + "https://cdn.discordapp.com/attachments/951441475034558484/951441880841854986/LO_NT_Grillers.png", + "https://cdn.discordapp.com/attachments/951441475034558484/951441897052864532/LO_HT_Grillers.png", + ], + rush: [ + "https://cdn.discordapp.com/attachments/951442362775765022/951442800166174782/LO_NT_Rush.png", + "https://cdn.discordapp.com/attachments/951442362775765022/951442813596360714/LO_HT_Rush.png", + ], + }, + ss: { + seeking: [ + "https://cdn.discordapp.com/attachments/865925063731445760/865926389223784468/SS_NT_Seeking.png", + "https://cdn.discordapp.com/attachments/865925063731445760/865926397561798656/SS_HT_Seeking.png", + ], + grillers: [ + "https://cdn.discordapp.com/attachments/951441475034558484/951441959510233118/SS_NT_Grillers.png", + "https://cdn.discordapp.com/attachments/951441475034558484/951441974198698005/SS_HT_Grillers.png", + ], + rush: [ + "https://cdn.discordapp.com/attachments/951442362775765022/951442852485935164/SS_NT_Rush.png", + "https://cdn.discordapp.com/attachments/951442362775765022/951442864305479710/SS_HT_Rush.png", + ], + }, + ap: { + seeking: [ + "https://cdn.discordapp.com/attachments/865925063731445760/865926537629663242/AP_NT_Seeking.png", + "https://cdn.discordapp.com/attachments/865925063731445760/865926546635620382/AP_HT_Seeking.png", + ], + grillers: [ + "https://cdn.discordapp.com/attachments/951441475034558484/951442012626878514/AP_NT_Grillers.png", + "https://cdn.discordapp.com/attachments/951441475034558484/951442021246201906/AP_HT_Grillers.png", + ], + rush: [ + "https://cdn.discordapp.com/attachments/951442362775765022/951442890721206312/AP_NT_Rush.png", + "https://cdn.discordapp.com/attachments/951442362775765022/951442901219561472/AP_HT_Rush.png", + ], + }, + fundamentals: + "https://docs.google.com/document/d/1WTDiKSzV3SaD8Sn7wWlGreE2Y4Y7UrOv3SSv7qtzvcg/edit?usp=sharing", + fundamentals2: "https://youtu.be/BvGbmLO94Po", + advanced: + "https://docs.google.com/document/d/16wcdlxqwqBvOnXIviB_ig0FS5_a96DKwYUIiGh6YHa8/edit?usp=sharing", + spawns: + "https://cdn.discordapp.com/attachments/836884751922757652/836886520250105886/SR_Time_Interval.png", + ballpoint: "https://youtu.be/oSf39Yn0wOU", + explo: "https://youtu.be/1qSW0_fA_L4", + dynamo: "https://youtu.be/GrCCAI8giKc", + bamboo: "https://youtu.be/yptwgqIoYiI", + hydra: "https://youtu.be/_YduyOTVoLk", +} as const; + +const COMMAND_NAME = "q"; + +export const questionCommand: BotCommand = { + name: COMMAND_NAME, + builder: new SlashCommandBuilder() + .setName(COMMAND_NAME) + .setDescription("wohoo"), + execute: async ({ interaction }) => { + return interaction.reply("Pong!"); + }, +}; +// const questionCommand: BotCommand = { +// name: "add", +// description: "Gives you the specified role", +// validGuilds: [ids.guilds.sro], +// execute: async ({ interaction }) => { +// let result: any = groupedLinks; +// console.log("args", args); +// for (const arg of args) { +// console.log("result", result); +// if (typeof result === "string" || !result) break; +// if (result.hasOwnProperty(arg)) { +// const value = result[arg]; +// result = value; +// } +// } + +// if (Array.isArray(result)) { +// result = result.join("\n"); +// } + +// if (typeof result !== "string") { +// await msg.channel.send( +// "Invalid parameters - use: `!q` to see the available parameters" +// ); +// return; +// } + +// await msg.channel.send(result); +// }, +// }; diff --git a/discord-bot/commands.ts b/discord-bot/deploy-commands.ts similarity index 73% rename from discord-bot/commands.ts rename to discord-bot/deploy-commands.ts index 741a28c64..a422af8ee 100644 --- a/discord-bot/commands.ts +++ b/discord-bot/deploy-commands.ts @@ -1,19 +1,15 @@ import "dotenv/config"; -import { SlashCommandBuilder } from "@discordjs/builders"; import { REST } from "@discordjs/rest"; import { Routes } from "discord-api-types/v9"; import invariant from "tiny-invariant"; +import { commands } from "./commands"; invariant(process.env["BOT_TOKEN"], "DISCORD_TOKEN must be set"); invariant(process.env["BOT_ID"], "BOT_ID must be set"); invariant(process.env["TEST_GUILD_ID"], "TEST_GUILD_ID must be set"); -const commands = [ - new SlashCommandBuilder() - .setName("ping") - .setDescription("Replies with pong!"), -].map((command) => command.toJSON()); +const serializedCommands = commands.map((cmd) => cmd.builder.toJSON()); const rest = new REST({ version: "9" }).setToken(process.env["BOT_TOKEN"]); @@ -23,7 +19,7 @@ rest process.env["BOT_ID"], process.env["TEST_GUILD_ID"] ), - { body: commands } + { body: serializedCommands } // TODO: divide by guild ) .then(() => console.log("Successfully registered application commands.")) .catch(console.error); diff --git a/discord-bot/ids.ts b/discord-bot/ids.ts new file mode 100644 index 000000000..18eb20e25 --- /dev/null +++ b/discord-bot/ids.ts @@ -0,0 +1,29 @@ +const ids = { + users: { + admin: "79237403620945920", + }, + roles: { + sroLfg: "749589703371653158", + sroCoach: "807258345223356486", + plusTwoPings: "678602424314888224", + plusThreePings: "818060819811663872", + plusOne: "657613334249734165", + plusTwo: "678169134416265260", + plusThree: "815267885601521696", + patreonSupporter: "787281384909045760", + patreonSupporterPlus: "787281624152801350", + patreonSupporterPlusPlus: "787281663138725928", + }, + channels: { + // Salmon Run // Plus Server + bot: ["746130457455886337", "808995745768013854"], + sroLfg: "745036737943699546", + }, + guilds: { + sro: "737359708276654121", + plusServer: "351828612208525333", + sendou: "299182152161951744", + }, +} as const; + +export default ids; diff --git a/discord-bot/index.ts b/discord-bot/index.ts index 4db523166..9d478f59b 100644 --- a/discord-bot/index.ts +++ b/discord-bot/index.ts @@ -2,6 +2,7 @@ import { Client, Intents } from "discord.js"; import "dotenv/config"; import invariant from "tiny-invariant"; +import { commandsMap } from "./commands"; invariant(process.env["BOT_TOKEN"], "DISCORD_TOKEN must be set"); @@ -15,10 +16,15 @@ client.on("interactionCreate", async (interaction) => { if (!interaction.isCommand()) return; const { commandName } = interaction; + const command = commandsMap[commandName]; - if (commandName === "ping") { - await interaction.reply("Pong!"); + if (!command) { + throw new Error( + `I don't know how to handle the command called "${commandName}"` + ); } + + return command.execute({ interaction }); }); client.login(process.env["BOT_TOKEN"]).catch((err) => console.error(err)); diff --git a/discord-bot/package.json b/discord-bot/package.json index 685c4fb79..e85f2c627 100644 --- a/discord-bot/package.json +++ b/discord-bot/package.json @@ -2,7 +2,7 @@ "name": "lohi", "scripts": { "dev": "ts-node index.ts", - "commands": "ts-node commands.ts", + "commands": "ts-node deploy-commands.ts", "test": "echo \"Error: no test specified\" && exit 1" }, "dependencies": { diff --git a/discord-bot/types.ts b/discord-bot/types.ts new file mode 100644 index 000000000..376034914 --- /dev/null +++ b/discord-bot/types.ts @@ -0,0 +1,13 @@ +import type { SlashCommandBuilder } from "@discordjs/builders"; +import type { CommandInteraction } from "discord.js"; + +export interface BotCommand { + name: string; + // description: string; + // /** ID's of guilds where this command will be set */ + // guilds: string[]; + builder: SlashCommandBuilder; + execute: (commandParameters: { + interaction: CommandInteraction; + }) => Promise; +}