From 0013af7c3bf43bd3b34e3a67b44ac1407cfa52fa Mon Sep 17 00:00:00 2001 From: fzzin <43480857+fzzinchemical@users.noreply.github.com> Date: Thu, 10 Apr 2025 13:26:57 +0200 Subject: [PATCH] refactor: update yandere message handling to use getPosts for embed generation and add tests --- src/plugins/yandere/api/api.ts | 4 ++++ src/plugins/yandere/messages.ts | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/plugins/yandere/api/api.ts b/src/plugins/yandere/api/api.ts index 08faec0..69400df 100644 --- a/src/plugins/yandere/api/api.ts +++ b/src/plugins/yandere/api/api.ts @@ -65,4 +65,8 @@ Deno.test("Post Request with tag", async() => { Deno.test("Post Request with limit", async() => { console.debug(await getPosts("[limit: 1)]")) +}) + +Deno.test("Post Request with page", async() => { + console.debug(await getPosts("[page: 30)]")) }) \ No newline at end of file diff --git a/src/plugins/yandere/messages.ts b/src/plugins/yandere/messages.ts index c901027..45dfecb 100644 --- a/src/plugins/yandere/messages.ts +++ b/src/plugins/yandere/messages.ts @@ -1,22 +1,28 @@ -import { Bot, DiscordEmbed, Embed, Message } from "npm:discordeno@18.0.1"; +import { Bot, Embed, Message } from "npm:discordeno@18.0.1"; import { defaultString } from "@root/defaultString.ts"; import { logMessage } from "@root/logging.ts"; -import { drop, requestWorker } from "@root/plugins/yandere/plugin.ts"; +import { getPosts } from "@root/plugins/yandere/api/api.ts"; export async function yandereMessageHandler(bot: Bot, message: Message) { const command = message.content.split(" ").slice(1).join(" "); - + const args = command.match(/(\[\.+\])/g) if (command === "drop") { + const embed = await getPosts("[limit: 1]") bot.helpers.sendMessage(message.channelId, { - embeds: [await drop()] + embeds: [embed as Embed] }) } else if (command.startsWith("drop [") && command.endsWith("]")) { logMessage(message); - const generatedEmbeds: Embed[] = await requestWorker(command); + 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], + embeds: [embed as Embed], }); } } } + +Deno.test("Test Bot Drop", async() => { + +}) \ No newline at end of file