refactor: streamline API request handling and enhance message processing
This commit is contained in:
@@ -1,69 +1,22 @@
|
||||
import { Bot, Message } from "npm:discordeno@18.0.1";
|
||||
import { dropYandere, dropYandere5, getPage, refresh, setPage } from "./api/api.ts";
|
||||
import { Bot, DiscordEmbed, 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";
|
||||
|
||||
export async function yandereMessageHandler(bot: Bot, message: Message) {
|
||||
const command = message.content.split(" ").slice(1).join(" ");
|
||||
const args = message.content.split(" ").slice(1);
|
||||
|
||||
switch (command) {
|
||||
case `drop`:
|
||||
logMessage(message);
|
||||
if (
|
||||
message.channelId === 754338073101205524n ||
|
||||
message.guildId === undefined
|
||||
) {
|
||||
await refresh();
|
||||
bot.helpers.sendMessage(message.channelId, {
|
||||
content: defaultString(await dropYandere()),
|
||||
});
|
||||
}
|
||||
break;
|
||||
case `drop 5`:
|
||||
logMessage(message);
|
||||
if (
|
||||
message.channelId === 754338073101205524n ||
|
||||
message.guildId === undefined
|
||||
) {
|
||||
await refresh();
|
||||
bot.helpers.sendMessage(message.channelId, {
|
||||
content: defaultString(await dropYandere5()),
|
||||
});
|
||||
}
|
||||
break;
|
||||
case `page`:
|
||||
logMessage(message);
|
||||
if (
|
||||
message.channelId === 754338073101205524n ||
|
||||
message.guildId === undefined
|
||||
) {
|
||||
if (args[0] === undefined) {
|
||||
bot.helpers.sendMessage(message.channelId, {
|
||||
content: "Please provide a page number",
|
||||
});
|
||||
} else if (isNaN(parseInt(args[0]))) {
|
||||
bot.helpers.sendMessage(message.channelId, {
|
||||
content: "Please provide a valid number",
|
||||
});
|
||||
} else {
|
||||
await setPage(parseInt(args[0]));
|
||||
bot.helpers.sendMessage(message.channelId, {
|
||||
content: "Page set to " + args[0],
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
case `getpage`:
|
||||
logMessage(message);
|
||||
if (
|
||||
message.channelId === 754338073101205524n ||
|
||||
message.guildId === undefined
|
||||
) {
|
||||
bot.helpers.sendMessage(message.channelId, {
|
||||
content: "Page is " + getPage(),
|
||||
});
|
||||
}
|
||||
break;
|
||||
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],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user