diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/deno.json b/deno.json index 758383d..d04c084 100755 --- a/deno.json +++ b/deno.json @@ -11,10 +11,10 @@ }, "tasks": { "dev": "deno run --watch --check src/bot.ts", - "admin": "deno -A --watch --check src/bot.ts" + "all": "deno -A --watch --check src/bot.ts" }, "imports": { - "@discordeno": "npm:discord.js@14.18.0", + "@discordjs": "npm:discord.js@14.18.0", "@melvdouc/xml-parser": "jsr:@melvdouc/xml-parser@^0.1.1", "@std/assert": "jsr:@std/assert@1", "@types/node": "npm:@types/node@^22.14.1", diff --git a/deno.lock b/deno.lock index 13bd7e3..acb96ec 100644 --- a/deno.lock +++ b/deno.lock @@ -3,20 +3,16 @@ "specifiers": { "jsr:@melvdouc/xml-parser@*": "0.1.1", "jsr:@melvdouc/xml-parser@~0.1.1": "0.1.1", - "jsr:@std/assert@*": "1.0.12", "jsr:@std/assert@1": "1.0.12", - "jsr:@std/dotenv@*": "0.225.2", - "jsr:@std/fmt@^1.0.2": "1.0.2", - "jsr:@std/fs@^1.0.3": "1.0.3", - "jsr:@std/html@1.0.2": "1.0.2", + "jsr:@std/dotenv@0.225.3": "0.225.3", + "jsr:@std/fmt@^1.0.5": "1.0.6", + "jsr:@std/fs@^1.0.11": "1.0.16", "jsr:@std/internal@^1.0.6": "1.0.6", - "jsr:@std/io@~0.224.7": "0.224.7", - "jsr:@std/log@*": "0.224.7", - "npm:@discordeno/bot@*": "19.0.0-next.b1bfe94", - "npm:@types/node@*": "18.16.19", + "jsr:@std/io@~0.225.2": "0.225.2", + "jsr:@std/log@*": "0.224.14", "npm:@types/node@^22.14.1": "22.14.1", "npm:discord.js@14.18.0": "14.18.0", - "npm:gson@*": "0.1.5" + "npm:discordeno@21.0.0": "21.0.0" }, "jsr": { "@melvdouc/xml-parser@0.1.1": { @@ -28,26 +24,23 @@ "jsr:@std/internal" ] }, - "@std/dotenv@0.225.2": { - "integrity": "e2025dce4de6c7bca21dece8baddd4262b09d5187217e231b033e088e0c4dd23" + "@std/dotenv@0.225.3": { + "integrity": "a95e5b812c27b0854c52acbae215856d9cce9d4bbf774d938c51d212711e8d4a" }, - "@std/fmt@1.0.2": { - "integrity": "87e9dfcdd3ca7c066e0c3c657c1f987c82888eb8103a3a3baa62684ffeb0f7a7" + "@std/fmt@1.0.6": { + "integrity": "a2c56a69a2369876ddb3ad6a500bb6501b5bad47bb3ea16bfb0c18974d2661fc" }, - "@std/fs@1.0.3": { - "integrity": "3cb839b1360b0a42d8b367c3093bfe4071798e6694fa44cf1963e04a8edba4fe" - }, - "@std/html@1.0.2": { - "integrity": "a8b830592c3f3c1e5595cb79328d714e14ba9e43d7d8a31da0b22810302a92e9" + "@std/fs@1.0.16": { + "integrity": "81878f62b6eeda0bf546197fc3daa5327c132fee1273f6113f940784a468b036" }, "@std/internal@1.0.6": { "integrity": "9533b128f230f73bd209408bb07a4b12f8d4255ab2a4d22a1fd6d87304aca9a4" }, - "@std/io@0.224.7": { - "integrity": "a70848793c44a7c100926571a8c9be68ba85487bfcd4d0540d86deabe1123dc9" + "@std/io@0.225.2": { + "integrity": "3c740cd4ee4c082e6cfc86458f47e2ab7cb353dc6234d5e9b1f91a2de5f4d6c7" }, - "@std/log@0.224.7": { - "integrity": "021941e5cd16de60cb11599c9b36f892aea95987fe66c753922808da27909e18", + "@std/log@0.224.14": { + "integrity": "257f7adceee3b53bb2bc86c7242e7d1bc59729e57d4981c4a7e5b876c808f05e", "dependencies": [ "jsr:@std/fmt", "jsr:@std/fs", @@ -56,21 +49,8 @@ } }, "npm": { - "@deno/shim-deno-test@0.3.3": { - "integrity": "sha512-Ge0Tnl7zZY0VvEfgsyLhjid8DzI1d0La0dgm+3m0/A8gZXgp5xwlyIyue5e4SCUuVB/3AH/0lun9LcJhhTwmbg==" - }, - "@deno/shim-deno@0.9.0": { - "integrity": "sha512-iP+qdI4Oy/Mw9yv40TqdjNKL+stpKDo8drki2cKisTXgZf+GoIdMhIuODxSypRyv6wxIuHNx7ZiKE3Sl3kAHuw==", - "dependencies": [ - "@deno/shim-deno-test", - "which" - ] - }, - "@deno/shim-timers@0.1.0": { - "integrity": "sha512-XFRnB5Rtbkd5RiYHwhugNK9gvDgYXmFTUOT5dmhWCKG7WnOWZggbJMnH1NcyYS3QgHvmaTOaHCyNFNSv57j3Dg==" - }, - "@discordeno/bot@19.0.0-next.b1bfe94": { - "integrity": "sha512-ZaPDaPM6tuxpRZCyuNB2rzqz2WYHH20IQdutu87jffW2dV26D3Nw8SJCE1LNdXdu9akes3VMXolkNsLJ5MW2Hw==", + "@discordeno/bot@21.0.0": { + "integrity": "sha512-x6EcVHBvWIhjY5/lcwgZzzCiqdpKFZqu2qUaZqKb7RYS8L8Q8zY40hCnbToVehLB8+BGcnHzxCeEvWWg8tnT/g==", "dependencies": [ "@discordeno/gateway", "@discordeno/rest", @@ -78,26 +58,27 @@ "@discordeno/utils" ] }, - "@discordeno/gateway@19.0.0-next.b1bfe94": { - "integrity": "sha512-rNkcCua4Inx8NkuCjbuRBAAg+AIg1qYb24Fq6/Y2+1s+iO0VSQ/ZK8PRNbI2gSpAtAbfndvxA9kyU1ggwwLjNw==", + "@discordeno/gateway@21.0.0": { + "integrity": "sha512-ur5Hatd1x86PPI4UnXKghAWat3vS90NvLJcpOSu1B1gYSENRZow8dohZ8Ov58SXWq5nZVuBYDJNCR248pWJvrg==", "dependencies": [ "@discordeno/types", "@discordeno/utils", + "fzstd", "ws" ] }, - "@discordeno/rest@19.0.0-next.b1bfe94": { - "integrity": "sha512-lLeP3hmMM0GFsO+VA3f9EKOwfIo1HvG1hudtlC1Er6BFWgArpz0/VizHbOyOr5SzZuzrQyfcBJJfEhC+48TsRg==", + "@discordeno/rest@21.0.0": { + "integrity": "sha512-ew5ddhUd7Qyv/GSzCy42bEmRv0yr2PspCMsLD/NeMiTLd3+OrVN5pAxBN9z+9JpS/daiiD/PVmvuUAVx/nXTEw==", "dependencies": [ "@discordeno/types", "@discordeno/utils" ] }, - "@discordeno/types@19.0.0-next.b1bfe94": { - "integrity": "sha512-X1MmdPFMyzjxFEANEPrrBjdJDJBAz4RTa1vpVlMp46C3dPqTwjMwijaPhPgPnFiSwt01lJ8WaFDpMvfqOwpQNg==" + "@discordeno/types@21.0.0": { + "integrity": "sha512-TUZAEqqlXRNQji+NCaQo8DruzI8rXbBvMaZYsZvN9f03PrdSddzMOy3cjs4eeL6ZMVocmMVRIaVnB713blylCw==" }, - "@discordeno/utils@19.0.0-next.b1bfe94": { - "integrity": "sha512-Y+j3G83vCVXiNSEQlFR9WWJ6GZhvBmIfFjb03zFcmHa20nHExILJJBEyDpS+ptziEyF7jB+2hNw5I/SKn8Zm2w==", + "@discordeno/utils@21.0.0": { + "integrity": "sha512-I7I3Szlk+LkT/CRmJJiLPsjuBUjbuXUCvOzsgWCltkxDMIGmQeNoQtFK7t89V1Gcc4icsrnHVMho1BcaAITijg==", "dependencies": [ "@discordeno/types" ] @@ -137,7 +118,7 @@ "discord-api-types", "magic-bytes.js", "tslib", - "undici@6.21.1" + "undici" ] }, "@discordjs/util@1.1.1": { @@ -157,9 +138,6 @@ "ws" ] }, - "@fastify/busboy@2.1.1": { - "integrity": "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==" - }, "@sapphire/async-queue@1.5.5": { "integrity": "sha512-cvGzxbba6sav2zZkH8GPf2oGk9yYoD5qrNWdu9fRehifgnFZJMV+nuy2nON2roRO4yQQ+v7MK/Pktl/HgfsUXg==" }, @@ -173,9 +151,6 @@ "@sapphire/snowflake@3.5.3": { "integrity": "sha512-jjmJywLAFoWeBi1W7994zZyiNWPIiqRRNAmSERxyg93xRGzNYvGjlZ0gR6x0F4gPRi2+0O6S71kOZYyr3cxaIQ==" }, - "@types/node@18.16.19": { - "integrity": "sha512-IXl7o+R9iti9eBW4Wg2hx1xQDig183jj7YLn8F7udNceyfkbn1ZxmzZXuak20gR40D7pIkIY1kYGx5VIGbaHKA==" - }, "@types/node@22.12.0": { "integrity": "sha512-Fll2FZ1riMjNmlmJOdAyY5pUbkftXslB5DgEzlIuNaiWhXd00FhWxVC/r4yV/4wBb9JfImTu+jiSvXTkJ7F/gA==", "dependencies": [ @@ -197,12 +172,6 @@ "@vladfrangu/async_event_emitter@2.4.6": { "integrity": "sha512-RaI5qZo6D2CVS6sTHFKg1v5Ohq/+Bo2LZ5gzUEwZ/WkHhwtGTCB/sVLw8ijOkAUxasZ+WshN/Rzj4ywsABJ5ZA==" }, - "circularjs@0.1.3": { - "integrity": "sha512-RVp6t82JlYMz6CxtGJVoncK7StrDuAIaihiE3dC4T3gE/Pko3ZGxoDibOctjcJKxAIb4C2avHOFA9mDxCKGbbw==", - "dependencies": [ - "underscore" - ] - }, "discord-api-types@0.37.120": { "integrity": "sha512-7xpNK0EiWjjDFp2nAhHXezE4OUWm7s1zhc/UXXN6hnFFU8dfoPHgV0Hx0RPiCa3ILRpdeh152icc68DGCyXYIw==" }, @@ -220,20 +189,24 @@ "fast-deep-equal", "lodash.snakecase", "tslib", - "undici@6.21.1" + "undici" + ] + }, + "discordeno@21.0.0": { + "integrity": "sha512-NX1x5GtHbrNhpeahfHw+2A6/3bpec2obNjIZ/mkBUGWcpLWG/ZgJSIkkdQIxcrnQ3loQooo/5IpBucnFTiGATA==", + "dependencies": [ + "@discordeno/bot", + "@discordeno/gateway", + "@discordeno/rest", + "@discordeno/types", + "@discordeno/utils" ] }, "fast-deep-equal@3.1.3": { "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, - "gson@0.1.5": { - "integrity": "sha512-EK+P+vGnmekaPMEg9qC23hTNgRaJ6GfQFS73sYgzvFoVYLMX7dVOUVDbPXRnNtnr99rf6DpOn4wlSbS0puN8AQ==", - "dependencies": [ - "circularjs" - ] - }, - "isexe@2.0.0": { - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" + "fzstd@0.1.1": { + "integrity": "sha512-dkuVSOKKwh3eas5VkJy1AW1vFpet8TA/fGmVA5krThl8YcOVE/8ZIoEA1+U1vEn5ckxxhLirSdY837azmbaNHA==" }, "lodash.snakecase@4.1.1": { "integrity": "sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==" @@ -250,41 +223,19 @@ "tslib@2.8.1": { "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==" }, - "underscore@1.6.0": { - "integrity": "sha512-z4o1fvKUojIWh9XuaVLUDdf86RQiq13AC1dmHbTpoyuu+bquHms76v16CjycCbec87J7z0k//SiQVk0sMdFmpQ==" - }, "undici-types@6.20.0": { "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==" }, "undici-types@6.21.0": { "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==" }, - "undici@5.28.4": { - "integrity": "sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==", - "dependencies": [ - "@fastify/busboy" - ] - }, "undici@6.21.1": { "integrity": "sha512-q/1rj5D0/zayJB2FraXdaWxbhWiNKDvu8naDT2dl1yTlvJp4BLtOcp2a5BvgGNQpYYJzau7tf1WgKv3b+7mqpQ==" }, - "which@2.0.2": { - "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", - "dependencies": [ - "isexe" - ] - }, - "ws@8.18.0": { - "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==" + "ws@8.18.1": { + "integrity": "sha512-RKW2aJZMXeMxVpnZ6bck+RswznaxmzdULiBr6KY7XkTnW8uvt0iT9H5DkHUChXrc+uurzwa0rVI16n/Xzjdz1w==" } }, - "redirects": { - "https://deno.land/x/dotenv/mod.ts": "https://deno.land/x/dotenv@v3.2.2/mod.ts" - }, - "remote": { - "https://deno.land/x/dotenv@v3.2.2/mod.ts": "077b48773de9205266a0b44c3c3a3c3083449ed64bb0b6cc461b95720678d38e", - "https://deno.land/x/dotenv@v3.2.2/util.ts": "693730877b13f8ead2b79b2aa31e2a0652862f7dc0c5f6d2f313f4d39c7b7670" - }, "workspace": { "dependencies": [ "jsr:@melvdouc/xml-parser@~0.1.1", diff --git a/src/bot.ts b/src/bot.ts index 89323f8..be2653c 100755 --- a/src/bot.ts +++ b/src/bot.ts @@ -1,24 +1,71 @@ -import { Client, Events, GatewayIntentBits } from '@discordeno'; -import { EnvConst, loadConfig } from "@root/core/configLoader.ts"; -import { messagehandler } from "@root/messages.ts"; +import { + Client, + Events, + GatewayIntentBits, + REST, + Routes, +} from "@discordjs"; +import * as stdDotenv from "jsr:@std/dotenv@0.225.3"; +import { commandRouter } from "@root/commands.ts"; +const env = await stdDotenv.load(); -const env: EnvConst = loadConfig(); +const token = env.TOKEN; +if (token === undefined) throw Error("no bot token"); +// import { EnvConst, loadConfig } from "@root/core/configLoader.ts"; +// import { messagehandler } from "@root/messages.ts"; +// const env: EnvConst = loadConfig(); +const { promise, resolve, reject } = Promise.withResolvers(); -const client = new Client({ intents: [GatewayIntentBits.Guilds] }); - -client.on(Events.ClientReady, readyClient => { - console.log(`Logged in as ${readyClient.user.tag}!`); +const client = new Client({ + intents: [ + GatewayIntentBits.Guilds, + GatewayIntentBits.DirectMessages, + ], }); -client.on(Events.InteractionCreate, async interaction => { - if (!interaction.isChatInputCommand()) return; - - messagehandler(interaction.command) - - if (interaction.commandName === 'ping') { - await interaction.reply('Pong!'); - } +client.on(Events.ClientReady, (readyClient) => { + console.log(`Logged in as ${readyClient.user.tag}!`); + resolve(); }); -client.login(env.BOT_TOKEN); \ No newline at end of file +client.on(Events.InteractionCreate, async (interaction) => { + // messagehandler(interaction.command) + if (!interaction.isChatInputCommand()) return; + + if (interaction.commandName === "ping") { + await interaction.reply("pong"); + } + if (interaction.commandName === "pong") { + // if (interaction.options.getString("something something")) + } +}); + +client.on(Events.Error, (e) => { + reject(e); +}); + +const commands = commandRouter() + +const rest = new REST({ version: "10" }).setToken(token); + +client.login(token); + +await promise; + +try { + console.log("Started refreshing application (/) commands."); + if (client.application === null) throw Error("client.application is null!!!"); + await rest.put( + Routes.applicationCommands(client.application.id), + { + body: commands, + }, + ); + + console.log("Successfully reloaded application (/) commands."); +} catch (error) { + console.error(error); +} + +// client.login(env.BOT_TOKEN); diff --git a/src/commands.ts b/src/commands.ts new file mode 100755 index 0000000..a22dbb8 --- /dev/null +++ b/src/commands.ts @@ -0,0 +1,6 @@ +import {commands as yandereCommands} from "./plugins/yandere/commands.ts"; +import {commands as ruleCommands} from "./plugins/rule34/commands.ts"; + +export function commandRouter() { + return [...yandereCommands, ...ruleCommands] +} diff --git a/src/logging.ts b/src/logging.ts index c27ca02..48b08dd 100755 --- a/src/logging.ts +++ b/src/logging.ts @@ -1,5 +1,5 @@ import * as stdlogger from "jsr:@std/log"; -import { Message } from "@discordeno"; +import { Message } from "@discordjs"; export function logMessage(message: Message) { return stdlogger.info( diff --git a/src/messages.ts b/src/messages.ts deleted file mode 100755 index 807d00b..0000000 --- a/src/messages.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { createBot, Bot, Message } from "@discordeno"; -import { yandereMessageHandler } from "@root/plugins/yandere/messages.ts"; -import { rule34MessageHandler } from "@root/plugins/rule34/messages.ts"; - -const prefix = Deno.env.get("BOT_PREFIX") ?? ""; -if (!prefix) { - throw new Error("BOT_PREFIX is missing!"); -} - -export async function messagehandler(message: Message) { - console.debug({message}) - const command = message.content.split(" ")[0]; - try { - switch (command) { - case `${prefix}rule`: { - await rule34MessageHandler(message); - break; - case `${prefix}yande`: - await yandereMessageHandler(message); - break; - } - } catch (e) { - console.error((e as Error).message); - } -} diff --git a/src/plugins/rule34/commands.ts b/src/plugins/rule34/commands.ts new file mode 100644 index 0000000..422a4c3 --- /dev/null +++ b/src/plugins/rule34/commands.ts @@ -0,0 +1,54 @@ +import { SlashCommandBuilder } from "@discordjs"; +// import { drop, help, requestWorker } from "./plugin.ts"; +import { logMessage } from "@root/logging.ts"; +import { defaultString } from "@root/defaultString.ts"; + +// export async function rule34MessageHandler(message: Message) { +// const command = message.content.trim().split(" ").slice(1).join(" "); +// if (command === "drop") { +// bot.helpers.sendMessage(message.channelId, { +// embeds: [await drop()] +// }) +// } else if (command.startsWith("drop [") && command.endsWith("]")) { +// logMessage(message); +// const generatedEmbeds: Embed[] = await requestWorker(command); +// for (const embed of generatedEmbeds) { +// bot.helpers.sendMessage(message.channelId, { +// embeds: [embed], +// }); +// } +// } else if (command === "help") { +// logMessage(message); + +// bot.helpers.sendMessage(message.channelId, { +// content: defaultString(help()), +// }); +// } else { +// drop(); +// } +// } + +export const commands = [ + new SlashCommandBuilder() + .setName("rule") + .setDescription("Drops one or multiple images using the rule34 API.") + .setNSFW(true) + .addSubcommand(subcommand => + subcommand + .setName("drop") + .setDescription("Drops one or multiple images using the rule34 API.") + + ), + new SlashCommandBuilder() + .setName('gif') + .setDescription('Sends a random gif!') + .addStringOption(option => + option.setName('category') + .setDescription('The gif category') + .setRequired(true) + .addChoices( + { name: 'Funny', value: 'gif_funny' }, + { name: 'Meme', value: 'gif_meme' }, + { name: 'Movie', value: 'gif_movie' }, + )) +] \ No newline at end of file diff --git a/src/plugins/rule34/messages.ts b/src/plugins/rule34/messages.ts deleted file mode 100644 index 23b6d2a..0000000 --- a/src/plugins/rule34/messages.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { Bot, Message } from "@discordeno"; -import { drop, help, requestWorker } from "./plugin.ts"; -import { logMessage } from "@root/logging.ts"; -import { defaultString } from "@root/defaultString.ts"; -import { Embed } from "@root/structures/embeds.ts"; - -export async function rule34MessageHandler(message: Message) { - const command = message.content.trim().split(" ").slice(1).join(" "); - if (command === "drop") { - bot.helpers.sendMessage(message.channelId, { - embeds: [await drop()] - }) - } else if (command.startsWith("drop [") && command.endsWith("]")) { - logMessage(message); - const generatedEmbeds: Embed[] = await requestWorker(command); - for (const embed of generatedEmbeds) { - bot.helpers.sendMessage(message.channelId, { - embeds: [embed], - }); - } - } else if (command === "help") { - logMessage(message); - - bot.helpers.sendMessage(message.channelId, { - content: defaultString(help()), - }); - } else { - drop(); - } -} \ No newline at end of file diff --git a/src/plugins/rule34/plugin.ts b/src/plugins/rule34/plugin.ts index 26dff01..4e9b911 100644 --- a/src/plugins/rule34/plugin.ts +++ b/src/plugins/rule34/plugin.ts @@ -1,6 +1,5 @@ import { assert } from "@std/assert/assert"; import { requestJSON } from "@root/structures/apiRequest.ts"; -import { Embed, EmbedAuthor, EmbedImage } from "@root/structures/embeds.ts"; import { ImageResponse, postUrl } from "./api.ts"; const keys = ["limit", "id", "pid", "tags"] as const; @@ -10,56 +9,56 @@ function isKey(key: string): key is PostKeys { return keys.includes(key as any); } -export async function drop() { - try { - const response = await requestJSON(`${postUrl}&limit=1`); - const img = response[0]; - if (img === undefined) throw Error("An undefined Array was given!"); - return new Embed( - `ID: ${img.id}`, - img.sample_url, - new EmbedAuthor(img.owner), - // [new EmbedField("Tags", img.tags, true)], - new EmbedImage(img.file_url, img.height, img.width), - ); - } catch (e) { - console.error((e as Error).message); - return new Embed( - "Error Message", - "https://gifdb.com/images/thumbnail/nuh-uh-demon-slayer-girl-hm7q3hqa4lnqyl6d.gif", - new EmbedAuthor("fzzinChemical"), - new EmbedImage( - "https://gifdb.com/images/thumbnail/nuh-uh-demon-slayer-girl-hm7q3hqa4lnqyl6d.gif", - 250, - 250, - ), - ); - } -} +// export async function drop() { +// try { +// const response = await requestJSON(`${postUrl}&limit=1`); +// const img = response[0]; +// if (img === undefined) throw Error("An undefined Array was given!"); +// return new Embed( +// `ID: ${img.id}`, +// img.sample_url, +// new EmbedAuthor(img.owner), +// // [new EmbedField("Tags", img.tags, true)], +// new EmbedImage(img.file_url, img.height, img.width), +// ); +// } catch (e) { +// console.error((e as Error).message); +// return new Embed( +// "Error Message", +// "https://gifdb.com/images/thumbnail/nuh-uh-demon-slayer-girl-hm7q3hqa4lnqyl6d.gif", +// new EmbedAuthor("fzzinChemical"), +// new EmbedImage( +// "https://gifdb.com/images/thumbnail/nuh-uh-demon-slayer-girl-hm7q3hqa4lnqyl6d.gif", +// 250, +// 250, +// ), +// ); +// } +// } -export async function requestWorker(requestString: string) { - try { - const response = await requestJSON( - generateRequestURL(requestString), - ); - const stack: Embed[] = []; - for (const img of response) { - stack.push( - new Embed( - `ID: ${img.id}`, - img.sample_url, - new EmbedAuthor(img.owner), - // [new EmbedField("Tags", img.tags, true)], - new EmbedImage(img.file_url, img.height, img.width), - ), - ); - } - return stack; - } catch (e) { - console.error((e as Error).message); - return []; - } -} +// export async function requestWorker(requestString: string) { +// try { +// const response = await requestJSON( +// generateRequestURL(requestString), +// ); +// const stack: Embed[] = []; +// for (const img of response) { +// stack.push( +// new Embed( +// `ID: ${img.id}`, +// img.sample_url, +// new EmbedAuthor(img.owner), +// // [new EmbedField("Tags", img.tags, true)], +// new EmbedImage(img.file_url, img.height, img.width), +// ), +// ); +// } +// return stack; +// } catch (e) { +// console.error((e as Error).message); +// return []; +// } +// } //TODO: get help in form of a nice beautiful format export function help() { diff --git a/src/plugins/yandere/commands.ts b/src/plugins/yandere/commands.ts new file mode 100644 index 0000000..e93c2d7 --- /dev/null +++ b/src/plugins/yandere/commands.ts @@ -0,0 +1,31 @@ +import { SlashCommandBuilder} from "@discordjs"; +import { logMessage } from "@root/logging.ts"; +import { getPosts } from "@root/plugins/yandere/api/api.ts"; + +// export async function yandereMessageHandler(message: Message) { +// const command = message.content.split(" ").slice(1).join(" "); +// const args = command.match(/(\[.+\])/g) +// if (command === "drop") { +// const embed: DiscordEmbed | undefined = (await getPosts("[limit: 1]"))[0] +// if (embed === undefined) throw Error("undefined embed") +// bot.helpers.sendMessage(message.channelId, { +// embeds: [embed] +// }) +// } else if (command.startsWith("drop [") && command.endsWith("]")) { +// logMessage(message); +// if (args === null) throw Error("args is null") +// const generatedEmbeds = await getPosts(args[0]); +// for (const embed of generatedEmbeds) { +// bot.helpers.sendMessage(message.channelId, { +// embeds: [embed], +// }); +// } +// } +// } + +export const commands = [ + new SlashCommandBuilder() + .setName("drop") + .setDescription("Drops one or multiple images using the yande.re API.") + .setNSFW(true) +] \ No newline at end of file diff --git a/src/plugins/yandere/messages.ts b/src/plugins/yandere/messages.ts deleted file mode 100644 index a880074..0000000 --- a/src/plugins/yandere/messages.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Bot, DiscordEmbed, Message} from "@discordeno"; -import { logMessage } from "@root/logging.ts"; -import { getPosts } from "@root/plugins/yandere/api/api.ts"; - -export async function yandereMessageHandler(message: Message) { - const command = message.content.split(" ").slice(1).join(" "); - const args = command.match(/(\[.+\])/g) - if (command === "drop") { - const embed: DiscordEmbed | undefined = (await getPosts("[limit: 1]"))[0] - if (embed === undefined) throw Error("undefined embed") - bot.helpers.sendMessage(message.channelId, { - embeds: [embed] - }) - } else if (command.startsWith("drop [") && command.endsWith("]")) { - logMessage(message); - if (args === null) throw Error("args is null") - const generatedEmbeds = await getPosts(args[0]); - for (const embed of generatedEmbeds) { - bot.helpers.sendMessage(message.channelId, { - embeds: [embed], - }); - } - } -} diff --git a/src/structures/embeds.ts b/src/structures/embeds.ts index 0412b05..e69de29 100644 --- a/src/structures/embeds.ts +++ b/src/structures/embeds.ts @@ -1,66 +0,0 @@ -import { DiscordEmbed, DiscordEmbedAuthor, DiscordEmbedField, DiscordEmbedImage } from "npm:discordeno@21.0.0"; - -export type Field = {name: string, value: string} - -export class Embed implements DiscordEmbed{ - title: string - url: string - author: DiscordEmbedAuthor - // fields: DiscordEmbedField[] - image: DiscordEmbedImage - // timestamp: Time - - constructor( - title: string, - url: string, - author:DiscordEmbedAuthor, - // fields: EmbedField[], - image: DiscordEmbedImage, - ){ - this.title = title - this.url = url - this.author = author - // this.fields= fields - this.image = image - - } - toJSON() { - return { - title: this.title, - url : this.url, - author: this.author, - // fields: this.fields, - image: this.image - } - } -} - -export class EmbedImage implements DiscordEmbedImage { - url: string - height: number - width: number - constructor(url: string, height: number, width : number){ - this.url = url - this.height = height - this.width = width - } -} - -export class EmbedAuthor implements DiscordEmbedAuthor { - name: string - constructor(name: string){ - this.name = name - } -} - -export class EmbedField implements DiscordEmbedField { - name: string - value: string - inline: boolean - - constructor(name: string, value: string, inline: boolean) { - this.name = name - this.value = value - this.inline = inline - } -} \ No newline at end of file