Breaking Changes!!! Changed discordeno to discord.js. Adaptation in progress.

This commit is contained in:
fzzinchemical
2025-04-14 23:18:43 +02:00
parent 59803fabd5
commit 1f3090d799
13 changed files with 251 additions and 307 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.env

View File

@@ -11,10 +11,10 @@
}, },
"tasks": { "tasks": {
"dev": "deno run --watch --check src/bot.ts", "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": { "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", "@melvdouc/xml-parser": "jsr:@melvdouc/xml-parser@^0.1.1",
"@std/assert": "jsr:@std/assert@1", "@std/assert": "jsr:@std/assert@1",
"@types/node": "npm:@types/node@^22.14.1", "@types/node": "npm:@types/node@^22.14.1",

135
deno.lock generated
View File

@@ -3,20 +3,16 @@
"specifiers": { "specifiers": {
"jsr:@melvdouc/xml-parser@*": "0.1.1", "jsr:@melvdouc/xml-parser@*": "0.1.1",
"jsr:@melvdouc/xml-parser@~0.1.1": "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/assert@1": "1.0.12",
"jsr:@std/dotenv@*": "0.225.2", "jsr:@std/dotenv@0.225.3": "0.225.3",
"jsr:@std/fmt@^1.0.2": "1.0.2", "jsr:@std/fmt@^1.0.5": "1.0.6",
"jsr:@std/fs@^1.0.3": "1.0.3", "jsr:@std/fs@^1.0.11": "1.0.16",
"jsr:@std/html@1.0.2": "1.0.2",
"jsr:@std/internal@^1.0.6": "1.0.6", "jsr:@std/internal@^1.0.6": "1.0.6",
"jsr:@std/io@~0.224.7": "0.224.7", "jsr:@std/io@~0.225.2": "0.225.2",
"jsr:@std/log@*": "0.224.7", "jsr:@std/log@*": "0.224.14",
"npm:@discordeno/bot@*": "19.0.0-next.b1bfe94",
"npm:@types/node@*": "18.16.19",
"npm:@types/node@^22.14.1": "22.14.1", "npm:@types/node@^22.14.1": "22.14.1",
"npm:discord.js@14.18.0": "14.18.0", "npm:discord.js@14.18.0": "14.18.0",
"npm:gson@*": "0.1.5" "npm:discordeno@21.0.0": "21.0.0"
}, },
"jsr": { "jsr": {
"@melvdouc/xml-parser@0.1.1": { "@melvdouc/xml-parser@0.1.1": {
@@ -28,26 +24,23 @@
"jsr:@std/internal" "jsr:@std/internal"
] ]
}, },
"@std/dotenv@0.225.2": { "@std/dotenv@0.225.3": {
"integrity": "e2025dce4de6c7bca21dece8baddd4262b09d5187217e231b033e088e0c4dd23" "integrity": "a95e5b812c27b0854c52acbae215856d9cce9d4bbf774d938c51d212711e8d4a"
}, },
"@std/fmt@1.0.2": { "@std/fmt@1.0.6": {
"integrity": "87e9dfcdd3ca7c066e0c3c657c1f987c82888eb8103a3a3baa62684ffeb0f7a7" "integrity": "a2c56a69a2369876ddb3ad6a500bb6501b5bad47bb3ea16bfb0c18974d2661fc"
}, },
"@std/fs@1.0.3": { "@std/fs@1.0.16": {
"integrity": "3cb839b1360b0a42d8b367c3093bfe4071798e6694fa44cf1963e04a8edba4fe" "integrity": "81878f62b6eeda0bf546197fc3daa5327c132fee1273f6113f940784a468b036"
},
"@std/html@1.0.2": {
"integrity": "a8b830592c3f3c1e5595cb79328d714e14ba9e43d7d8a31da0b22810302a92e9"
}, },
"@std/internal@1.0.6": { "@std/internal@1.0.6": {
"integrity": "9533b128f230f73bd209408bb07a4b12f8d4255ab2a4d22a1fd6d87304aca9a4" "integrity": "9533b128f230f73bd209408bb07a4b12f8d4255ab2a4d22a1fd6d87304aca9a4"
}, },
"@std/io@0.224.7": { "@std/io@0.225.2": {
"integrity": "a70848793c44a7c100926571a8c9be68ba85487bfcd4d0540d86deabe1123dc9" "integrity": "3c740cd4ee4c082e6cfc86458f47e2ab7cb353dc6234d5e9b1f91a2de5f4d6c7"
}, },
"@std/log@0.224.7": { "@std/log@0.224.14": {
"integrity": "021941e5cd16de60cb11599c9b36f892aea95987fe66c753922808da27909e18", "integrity": "257f7adceee3b53bb2bc86c7242e7d1bc59729e57d4981c4a7e5b876c808f05e",
"dependencies": [ "dependencies": [
"jsr:@std/fmt", "jsr:@std/fmt",
"jsr:@std/fs", "jsr:@std/fs",
@@ -56,21 +49,8 @@
} }
}, },
"npm": { "npm": {
"@deno/shim-deno-test@0.3.3": { "@discordeno/bot@21.0.0": {
"integrity": "sha512-Ge0Tnl7zZY0VvEfgsyLhjid8DzI1d0La0dgm+3m0/A8gZXgp5xwlyIyue5e4SCUuVB/3AH/0lun9LcJhhTwmbg==" "integrity": "sha512-x6EcVHBvWIhjY5/lcwgZzzCiqdpKFZqu2qUaZqKb7RYS8L8Q8zY40hCnbToVehLB8+BGcnHzxCeEvWWg8tnT/g==",
},
"@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==",
"dependencies": [ "dependencies": [
"@discordeno/gateway", "@discordeno/gateway",
"@discordeno/rest", "@discordeno/rest",
@@ -78,26 +58,27 @@
"@discordeno/utils" "@discordeno/utils"
] ]
}, },
"@discordeno/gateway@19.0.0-next.b1bfe94": { "@discordeno/gateway@21.0.0": {
"integrity": "sha512-rNkcCua4Inx8NkuCjbuRBAAg+AIg1qYb24Fq6/Y2+1s+iO0VSQ/ZK8PRNbI2gSpAtAbfndvxA9kyU1ggwwLjNw==", "integrity": "sha512-ur5Hatd1x86PPI4UnXKghAWat3vS90NvLJcpOSu1B1gYSENRZow8dohZ8Ov58SXWq5nZVuBYDJNCR248pWJvrg==",
"dependencies": [ "dependencies": [
"@discordeno/types", "@discordeno/types",
"@discordeno/utils", "@discordeno/utils",
"fzstd",
"ws" "ws"
] ]
}, },
"@discordeno/rest@19.0.0-next.b1bfe94": { "@discordeno/rest@21.0.0": {
"integrity": "sha512-lLeP3hmMM0GFsO+VA3f9EKOwfIo1HvG1hudtlC1Er6BFWgArpz0/VizHbOyOr5SzZuzrQyfcBJJfEhC+48TsRg==", "integrity": "sha512-ew5ddhUd7Qyv/GSzCy42bEmRv0yr2PspCMsLD/NeMiTLd3+OrVN5pAxBN9z+9JpS/daiiD/PVmvuUAVx/nXTEw==",
"dependencies": [ "dependencies": [
"@discordeno/types", "@discordeno/types",
"@discordeno/utils" "@discordeno/utils"
] ]
}, },
"@discordeno/types@19.0.0-next.b1bfe94": { "@discordeno/types@21.0.0": {
"integrity": "sha512-X1MmdPFMyzjxFEANEPrrBjdJDJBAz4RTa1vpVlMp46C3dPqTwjMwijaPhPgPnFiSwt01lJ8WaFDpMvfqOwpQNg==" "integrity": "sha512-TUZAEqqlXRNQji+NCaQo8DruzI8rXbBvMaZYsZvN9f03PrdSddzMOy3cjs4eeL6ZMVocmMVRIaVnB713blylCw=="
}, },
"@discordeno/utils@19.0.0-next.b1bfe94": { "@discordeno/utils@21.0.0": {
"integrity": "sha512-Y+j3G83vCVXiNSEQlFR9WWJ6GZhvBmIfFjb03zFcmHa20nHExILJJBEyDpS+ptziEyF7jB+2hNw5I/SKn8Zm2w==", "integrity": "sha512-I7I3Szlk+LkT/CRmJJiLPsjuBUjbuXUCvOzsgWCltkxDMIGmQeNoQtFK7t89V1Gcc4icsrnHVMho1BcaAITijg==",
"dependencies": [ "dependencies": [
"@discordeno/types" "@discordeno/types"
] ]
@@ -137,7 +118,7 @@
"discord-api-types", "discord-api-types",
"magic-bytes.js", "magic-bytes.js",
"tslib", "tslib",
"undici@6.21.1" "undici"
] ]
}, },
"@discordjs/util@1.1.1": { "@discordjs/util@1.1.1": {
@@ -157,9 +138,6 @@
"ws" "ws"
] ]
}, },
"@fastify/busboy@2.1.1": {
"integrity": "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA=="
},
"@sapphire/async-queue@1.5.5": { "@sapphire/async-queue@1.5.5": {
"integrity": "sha512-cvGzxbba6sav2zZkH8GPf2oGk9yYoD5qrNWdu9fRehifgnFZJMV+nuy2nON2roRO4yQQ+v7MK/Pktl/HgfsUXg==" "integrity": "sha512-cvGzxbba6sav2zZkH8GPf2oGk9yYoD5qrNWdu9fRehifgnFZJMV+nuy2nON2roRO4yQQ+v7MK/Pktl/HgfsUXg=="
}, },
@@ -173,9 +151,6 @@
"@sapphire/snowflake@3.5.3": { "@sapphire/snowflake@3.5.3": {
"integrity": "sha512-jjmJywLAFoWeBi1W7994zZyiNWPIiqRRNAmSERxyg93xRGzNYvGjlZ0gR6x0F4gPRi2+0O6S71kOZYyr3cxaIQ==" "integrity": "sha512-jjmJywLAFoWeBi1W7994zZyiNWPIiqRRNAmSERxyg93xRGzNYvGjlZ0gR6x0F4gPRi2+0O6S71kOZYyr3cxaIQ=="
}, },
"@types/node@18.16.19": {
"integrity": "sha512-IXl7o+R9iti9eBW4Wg2hx1xQDig183jj7YLn8F7udNceyfkbn1ZxmzZXuak20gR40D7pIkIY1kYGx5VIGbaHKA=="
},
"@types/node@22.12.0": { "@types/node@22.12.0": {
"integrity": "sha512-Fll2FZ1riMjNmlmJOdAyY5pUbkftXslB5DgEzlIuNaiWhXd00FhWxVC/r4yV/4wBb9JfImTu+jiSvXTkJ7F/gA==", "integrity": "sha512-Fll2FZ1riMjNmlmJOdAyY5pUbkftXslB5DgEzlIuNaiWhXd00FhWxVC/r4yV/4wBb9JfImTu+jiSvXTkJ7F/gA==",
"dependencies": [ "dependencies": [
@@ -197,12 +172,6 @@
"@vladfrangu/async_event_emitter@2.4.6": { "@vladfrangu/async_event_emitter@2.4.6": {
"integrity": "sha512-RaI5qZo6D2CVS6sTHFKg1v5Ohq/+Bo2LZ5gzUEwZ/WkHhwtGTCB/sVLw8ijOkAUxasZ+WshN/Rzj4ywsABJ5ZA==" "integrity": "sha512-RaI5qZo6D2CVS6sTHFKg1v5Ohq/+Bo2LZ5gzUEwZ/WkHhwtGTCB/sVLw8ijOkAUxasZ+WshN/Rzj4ywsABJ5ZA=="
}, },
"circularjs@0.1.3": {
"integrity": "sha512-RVp6t82JlYMz6CxtGJVoncK7StrDuAIaihiE3dC4T3gE/Pko3ZGxoDibOctjcJKxAIb4C2avHOFA9mDxCKGbbw==",
"dependencies": [
"underscore"
]
},
"discord-api-types@0.37.120": { "discord-api-types@0.37.120": {
"integrity": "sha512-7xpNK0EiWjjDFp2nAhHXezE4OUWm7s1zhc/UXXN6hnFFU8dfoPHgV0Hx0RPiCa3ILRpdeh152icc68DGCyXYIw==" "integrity": "sha512-7xpNK0EiWjjDFp2nAhHXezE4OUWm7s1zhc/UXXN6hnFFU8dfoPHgV0Hx0RPiCa3ILRpdeh152icc68DGCyXYIw=="
}, },
@@ -220,20 +189,24 @@
"fast-deep-equal", "fast-deep-equal",
"lodash.snakecase", "lodash.snakecase",
"tslib", "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": { "fast-deep-equal@3.1.3": {
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="
}, },
"gson@0.1.5": { "fzstd@0.1.1": {
"integrity": "sha512-EK+P+vGnmekaPMEg9qC23hTNgRaJ6GfQFS73sYgzvFoVYLMX7dVOUVDbPXRnNtnr99rf6DpOn4wlSbS0puN8AQ==", "integrity": "sha512-dkuVSOKKwh3eas5VkJy1AW1vFpet8TA/fGmVA5krThl8YcOVE/8ZIoEA1+U1vEn5ckxxhLirSdY837azmbaNHA=="
"dependencies": [
"circularjs"
]
},
"isexe@2.0.0": {
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw=="
}, },
"lodash.snakecase@4.1.1": { "lodash.snakecase@4.1.1": {
"integrity": "sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==" "integrity": "sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw=="
@@ -250,41 +223,19 @@
"tslib@2.8.1": { "tslib@2.8.1": {
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==" "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="
}, },
"underscore@1.6.0": {
"integrity": "sha512-z4o1fvKUojIWh9XuaVLUDdf86RQiq13AC1dmHbTpoyuu+bquHms76v16CjycCbec87J7z0k//SiQVk0sMdFmpQ=="
},
"undici-types@6.20.0": { "undici-types@6.20.0": {
"integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==" "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="
}, },
"undici-types@6.21.0": { "undici-types@6.21.0": {
"integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==" "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="
}, },
"undici@5.28.4": {
"integrity": "sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==",
"dependencies": [
"@fastify/busboy"
]
},
"undici@6.21.1": { "undici@6.21.1": {
"integrity": "sha512-q/1rj5D0/zayJB2FraXdaWxbhWiNKDvu8naDT2dl1yTlvJp4BLtOcp2a5BvgGNQpYYJzau7tf1WgKv3b+7mqpQ==" "integrity": "sha512-q/1rj5D0/zayJB2FraXdaWxbhWiNKDvu8naDT2dl1yTlvJp4BLtOcp2a5BvgGNQpYYJzau7tf1WgKv3b+7mqpQ=="
}, },
"which@2.0.2": { "ws@8.18.1": {
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", "integrity": "sha512-RKW2aJZMXeMxVpnZ6bck+RswznaxmzdULiBr6KY7XkTnW8uvt0iT9H5DkHUChXrc+uurzwa0rVI16n/Xzjdz1w=="
"dependencies": [
"isexe"
]
},
"ws@8.18.0": {
"integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw=="
} }
}, },
"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": { "workspace": {
"dependencies": [ "dependencies": [
"jsr:@melvdouc/xml-parser@~0.1.1", "jsr:@melvdouc/xml-parser@~0.1.1",

View File

@@ -1,24 +1,71 @@
import { Client, Events, GatewayIntentBits } from '@discordeno'; import {
import { EnvConst, loadConfig } from "@root/core/configLoader.ts"; Client,
import { messagehandler } from "@root/messages.ts"; 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<void>();
const client = new Client({ intents: [GatewayIntentBits.Guilds] }); const client = new Client({
intents: [
client.on(Events.ClientReady, readyClient => { GatewayIntentBits.Guilds,
console.log(`Logged in as ${readyClient.user.tag}!`); GatewayIntentBits.DirectMessages,
],
}); });
client.on(Events.InteractionCreate, async interaction => { client.on(Events.ClientReady, (readyClient) => {
console.log(`Logged in as ${readyClient.user.tag}!`);
resolve();
});
client.on(Events.InteractionCreate, async (interaction) => {
// messagehandler(interaction.command)
if (!interaction.isChatInputCommand()) return; if (!interaction.isChatInputCommand()) return;
messagehandler(interaction.command) if (interaction.commandName === "ping") {
await interaction.reply("pong");
if (interaction.commandName === 'ping') { }
await interaction.reply('Pong!'); if (interaction.commandName === "pong") {
// if (interaction.options.getString("something something"))
} }
}); });
client.login(env.BOT_TOKEN); 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);

6
src/commands.ts Executable file
View File

@@ -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]
}

View File

@@ -1,5 +1,5 @@
import * as stdlogger from "jsr:@std/log"; import * as stdlogger from "jsr:@std/log";
import { Message } from "@discordeno"; import { Message } from "@discordjs";
export function logMessage(message: Message) { export function logMessage(message: Message) {
return stdlogger.info( return stdlogger.info(

View File

@@ -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);
}
}

View File

@@ -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' },
))
]

View File

@@ -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();
}
}

View File

@@ -1,6 +1,5 @@
import { assert } from "@std/assert/assert"; import { assert } from "@std/assert/assert";
import { requestJSON } from "@root/structures/apiRequest.ts"; import { requestJSON } from "@root/structures/apiRequest.ts";
import { Embed, EmbedAuthor, EmbedImage } from "@root/structures/embeds.ts";
import { ImageResponse, postUrl } from "./api.ts"; import { ImageResponse, postUrl } from "./api.ts";
const keys = ["limit", "id", "pid", "tags"] as const; 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); return keys.includes(key as any);
} }
export async function drop() { // export async function drop() {
try { // try {
const response = await requestJSON<ImageResponse[]>(`${postUrl}&limit=1`); // const response = await requestJSON<ImageResponse[]>(`${postUrl}&limit=1`);
const img = response[0]; // const img = response[0];
if (img === undefined) throw Error("An undefined Array was given!"); // if (img === undefined) throw Error("An undefined Array was given!");
return new Embed( // return new Embed(
`ID: ${img.id}`, // `ID: ${img.id}`,
img.sample_url, // img.sample_url,
new EmbedAuthor(img.owner), // new EmbedAuthor(img.owner),
// [new EmbedField("Tags", img.tags, true)], // // [new EmbedField("Tags", img.tags, true)],
new EmbedImage(img.file_url, img.height, img.width), // new EmbedImage(img.file_url, img.height, img.width),
); // );
} catch (e) { // } catch (e) {
console.error((e as Error).message); // console.error((e as Error).message);
return new Embed( // return new Embed(
"Error Message", // "Error Message",
"https://gifdb.com/images/thumbnail/nuh-uh-demon-slayer-girl-hm7q3hqa4lnqyl6d.gif", // "https://gifdb.com/images/thumbnail/nuh-uh-demon-slayer-girl-hm7q3hqa4lnqyl6d.gif",
new EmbedAuthor("fzzinChemical"), // new EmbedAuthor("fzzinChemical"),
new EmbedImage( // new EmbedImage(
"https://gifdb.com/images/thumbnail/nuh-uh-demon-slayer-girl-hm7q3hqa4lnqyl6d.gif", // "https://gifdb.com/images/thumbnail/nuh-uh-demon-slayer-girl-hm7q3hqa4lnqyl6d.gif",
250, // 250,
250, // 250,
), // ),
); // );
} // }
} // }
export async function requestWorker(requestString: string) { // export async function requestWorker(requestString: string) {
try { // try {
const response = await requestJSON<ImageResponse[]>( // const response = await requestJSON<ImageResponse[]>(
generateRequestURL(requestString), // generateRequestURL(requestString),
); // );
const stack: Embed[] = []; // const stack: Embed[] = [];
for (const img of response) { // for (const img of response) {
stack.push( // stack.push(
new Embed( // new Embed(
`ID: ${img.id}`, // `ID: ${img.id}`,
img.sample_url, // img.sample_url,
new EmbedAuthor(img.owner), // new EmbedAuthor(img.owner),
// [new EmbedField("Tags", img.tags, true)], // // [new EmbedField("Tags", img.tags, true)],
new EmbedImage(img.file_url, img.height, img.width), // new EmbedImage(img.file_url, img.height, img.width),
), // ),
); // );
} // }
return stack; // return stack;
} catch (e) { // } catch (e) {
console.error((e as Error).message); // console.error((e as Error).message);
return []; // return [];
} // }
} // }
//TODO: get help in form of a nice beautiful format //TODO: get help in form of a nice beautiful format
export function help() { export function help() {

View File

@@ -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)
]

View File

@@ -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],
});
}
}
}

View File

@@ -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
}
}