Skip to content

Commit 9708544

Browse files
committed
Handle deleted polls
1 parent 88013d1 commit 9708544

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/handler/messageDeleteHandler.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import type { ClientUser, Message } from "discord.js";
22

33
import type { BotContext } from "@/context.js";
44

5+
import * as pollService from "@/service/poll.js";
6+
7+
import log from "@log";
8+
59
const deleteInlineRepliesFromBot = (messageRef: Message<true>, botUser: ClientUser) =>
610
Promise.allSettled(
711
messageRef.channel.messages.cache
@@ -17,6 +21,8 @@ export default async function (message: Message<true>, context: BotContext) {
1721
return;
1822
}
1923

24+
await handlePollDeletion(message);
25+
2026
const isNormalCommand =
2127
message.content.startsWith(context.prefix.command) ||
2228
message.content.startsWith(context.prefix.modCommand);
@@ -25,3 +31,13 @@ export default async function (message: Message<true>, context: BotContext) {
2531
await deleteInlineRepliesFromBot(message, context.client.user);
2632
}
2733
}
34+
35+
async function handlePollDeletion(message: Message<true>) {
36+
const foundPoll = await pollService.findPollForEmbedMessage(message);
37+
if (!foundPoll) {
38+
return;
39+
}
40+
41+
const deletedPoll = await pollService.deletePoll(foundPoll.id);
42+
log.info(deletedPoll, "Poll deleted");
43+
}

0 commit comments

Comments
 (0)