Files
Hotodog-Discord-Bot/src/plugins/yandere/messages.ts

24 lines
930 B
TypeScript

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(bot: Bot, 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],
});
}
}
}