diff --git a/.env.example b/.env.example index 2298efa..dfea397 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,5 @@ DISCORD_ID= DISCORD_TOKEN= -DISCORD_SECRET= \ No newline at end of file +DISCORD_SECRET= + +OLLAMA_API= \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 0967ef4..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/bin/delete.js b/bin/delete.js index 89398ea..49b79fb 100644 --- a/bin/delete.js +++ b/bin/delete.js @@ -2,18 +2,15 @@ import { logger } from "@discordeno/utils"; import REST from "../src/lib/handlers/RESTHandler"; import * as InteractionHandler from "../src/lib/handlers/InteractionHandler"; -import * as CommandHandler from "../src/lib/handlers/CommandHandler"; await InteractionHandler.load(); const registered = await REST.getGlobalApplicationCommands(); -for (let { id, name, type } of registered) { - const cmd = CommandHandler.commands.get(name); - if (cmd && cmd.type == type) continue; - +const id = process.argv[2]; +const cmd = registered.find((_) => _.id === id); +if (cmd) { await REST.deleteGlobalApplicationCommand(id); - - logger.info(`Deleted ${name}(${id})`); + logger.info(`Deleted ${cmd.name}(${id})`); } process.exit(); diff --git a/bin/list.js b/bin/list.js index ec4efee..5fd8ed2 100644 --- a/bin/list.js +++ b/bin/list.js @@ -5,16 +5,16 @@ const registered = await REST.getGlobalApplicationCommands(); const TYPES = ["CHAT_INPUT", "USER", "MESSAGE"]; -logger.info("┌" + "-".repeat(58) + "┐"); -logger.info("| " + "ID".padEnd(24, " ") + " | " + "NAME".padEnd(16, " ") + " | " + "TYPE".padEnd(10, " ") + " |"); -logger.info("├" + "-".repeat(58) + "┤"); +logger.info("┌" + "-".repeat(58 + 8) + "┐"); +logger.info("| " + "ID".padEnd(24, " ") + " | " + "NAME".padEnd(24, " ") + " | " + "TYPE".padEnd(10, " ") + " |"); +logger.info("├" + "-".repeat(58 + 8) + "┤"); for (let { id, name, type } of registered) { logger.info( - "| " + id.padEnd(24, " ") + " | " + name.padEnd(16, " ") + " | " + TYPES[type - 1].padEnd(10, " ") + " |", + "| " + id.padEnd(24, " ") + " | " + name.padEnd(24, " ") + " | " + TYPES[type - 1].padEnd(10, " ") + " |", ); } -logger.info("└" + "-".repeat(58) + "┘"); +logger.info("└" + "-".repeat(58 + 8) + "┘"); process.exit(); diff --git a/bin/update.js b/bin/update.js index dbdc4b4..17db8d7 100644 --- a/bin/update.js +++ b/bin/update.js @@ -11,7 +11,7 @@ for (let [key, value] of CommandHandler.commands.entries()) { headers: { "Content-Type": "application/json", Authorization: "Bot " + process.env.DISCORD_TOKEN }, body: JSON.stringify({ name: value.name, - type: value.type, + type: value.commandType, description: value?.description || "", options: value?.options, nsfw: value?.nsfw, @@ -21,8 +21,11 @@ for (let [key, value] of CommandHandler.commands.entries()) { }); const command = await response.json(); - - logger.info(`Registered ${command.name}(${command.id})`); + if (command.id) logger.info(`Registered ${command.name}(${command.id})(type:${value.type})`); + else { + logger.error(`Failed to register new command ${value.name}(type:${value.type})`); + console.log(JSON.stringify(command.errors, null, 4)); + } } process.exit(); diff --git a/src/interactions/bizz.ts b/src/interactions/bizz.ts new file mode 100644 index 0000000..a87c3ee --- /dev/null +++ b/src/interactions/bizz.ts @@ -0,0 +1,20 @@ +import type { Command } from "../lib/types/command"; +import { InteractionResponseTypes } from "@discordeno/bot"; +import UserCommand from "../lib/classes/UserCommand"; + +export default class extends UserCommand implements Command { + name = "Bizz"; + description = ""; + options = []; + + constructor() { + super(); + } + + async run() { + return { + type: InteractionResponseTypes.ChannelMessageWithSource, + data: { content: "<:FvU757MaYAAb_G9:1265558339283320864>" }, + }; + } +} diff --git a/src/interactions/default.ts b/src/interactions/foo.ts similarity index 75% rename from src/interactions/default.ts rename to src/interactions/foo.ts index dcec7af..8f20a4b 100644 --- a/src/interactions/default.ts +++ b/src/interactions/foo.ts @@ -3,8 +3,8 @@ import { InteractionResponseTypes } from "@discordeno/bot"; import SlashCommand from "../lib/classes/SlashCommand"; export default class extends SlashCommand implements Command { - name = "default"; - description = "default"; + name = "foo"; + description = "Foo"; options = []; constructor() { @@ -14,7 +14,7 @@ export default class extends SlashCommand implements Command { async run() { return { type: InteractionResponseTypes.ChannelMessageWithSource, - data: { content: "my name is terry and im going to destroy thgis world" }, + data: { content: "Bar" }, }; } } diff --git a/src/interactions/send.ts b/src/interactions/send.ts deleted file mode 100644 index ae32921..0000000 --- a/src/interactions/send.ts +++ /dev/null @@ -1,72 +0,0 @@ -import type { Command } from "../lib/types/command"; -import { MessageComponentTypes, TextStyles } from "@discordeno/bot"; -import SlashCommand from "../lib/classes/SlashCommand"; -import Modal from "../lib/classes/Modal"; -import { collectModal } from "../lib/handlers/ModalHandler"; - -interface SendMailResponse { - success: boolean; - message: string; -} - -export default class extends SlashCommand implements Command { - name = "send"; - description = "Send mail to a user in the Enigmatica 9 server!"; - options = []; - - constructor() { - super(); - } - - async run() { - const modal = new Modal().setTitle("Send Mail").setComponents([ - { - type: MessageComponentTypes.ActionRow, - components: [ - { - type: MessageComponentTypes.InputText, - customId: "recipient", - style: TextStyles.Short, - label: "Recipient", - }, - ], - }, - { - type: MessageComponentTypes.ActionRow, - components: [ - { - type: MessageComponentTypes.InputText, - customId: "content", - style: TextStyles.Paragraph, - label: "Message", - }, - ], - }, - ]); - - collectModal(modal) - .then(async ({ interaction, values }) => { - if (!interaction.data?.components) return; - const user = interaction?.member?.user || { username: "[unknown]" }; - - try { - const response = await fetch(process.env.MAIL_SERVER + "/send", { - method: "POST", - body: JSON.stringify({ - author: user.username, - recipient: values.get("recipient"), - content: values.get("content"), - }), - }); - - const body = (await response.json()) as SendMailResponse; - interaction.respond(body.message); - } catch (e) { - return interaction.respond((e as Error).message); - } - }) - .catch((_) => {}); - - return modal; - } -} diff --git a/src/interactions/upload.ts b/src/interactions/upload.ts new file mode 100644 index 0000000..2dd1671 --- /dev/null +++ b/src/interactions/upload.ts @@ -0,0 +1,20 @@ +import type { Command } from "../lib/types/command"; +import { InteractionResponseTypes } from "@discordeno/bot"; +import MessageCommand from "../lib/classes/MessageCommand"; + +export default class extends MessageCommand implements Command { + name = "Upload to snep.lol"; + description = ""; + options = []; + + constructor() { + super(); + } + + async run() { + return { + type: InteractionResponseTypes.ChannelMessageWithSource, + data: { content: "MY NUTS LMAO" }, + }; + } +} diff --git a/src/lib/classes/ApplicationCommand.ts b/src/lib/classes/ApplicationCommand.ts index 2c90c0b..0a2e781 100644 --- a/src/lib/classes/ApplicationCommand.ts +++ b/src/lib/classes/ApplicationCommand.ts @@ -1,5 +1,5 @@ import { InteractionTypes } from "@discordeno/types"; export default class ApplicationCommand { - static type = InteractionTypes.ApplicationCommand; + type = InteractionTypes.ApplicationCommand; } diff --git a/src/lib/classes/MessageCommand.ts b/src/lib/classes/MessageCommand.ts index dd6225b..3843e42 100644 --- a/src/lib/classes/MessageCommand.ts +++ b/src/lib/classes/MessageCommand.ts @@ -2,5 +2,5 @@ import { ApplicationCommandTypes } from "@discordeno/types"; import ApplicationCommand from "./ApplicationCommand"; export default class SlashCommand extends ApplicationCommand { - static commandType = ApplicationCommandTypes.Message; + commandType = ApplicationCommandTypes.Message; } diff --git a/src/lib/classes/SlashCommand.ts b/src/lib/classes/SlashCommand.ts index 856ced1..f1c4cde 100644 --- a/src/lib/classes/SlashCommand.ts +++ b/src/lib/classes/SlashCommand.ts @@ -2,5 +2,5 @@ import { ApplicationCommandTypes } from "@discordeno/types"; import ApplicationCommand from "./ApplicationCommand"; export default class SlashCommand extends ApplicationCommand { - static commandType = ApplicationCommandTypes.ChatInput; + commandType = ApplicationCommandTypes.ChatInput; } diff --git a/src/lib/classes/UserCommand.ts b/src/lib/classes/UserCommand.ts index edb3bbe..b1267f9 100644 --- a/src/lib/classes/UserCommand.ts +++ b/src/lib/classes/UserCommand.ts @@ -2,5 +2,5 @@ import { ApplicationCommandTypes } from "@discordeno/types"; import ApplicationCommand from "./ApplicationCommand"; export default class SlashCommand extends ApplicationCommand { - static commandType = ApplicationCommandTypes.User; + commandType = ApplicationCommandTypes.User; }