zappyzep/backend/src/plugins/Reminders/commands/RemindersDeleteCmd.ts
Dragory c7751a9da1
Centralize periodic checks for mutes, tempbans, vcalerts, reminders, and scheduled posts
This should result in a significant performance improvement.
The new method is also more precise than the old one, allowing
the aforementioned checks to be performed with second-precision.
2021-09-25 21:34:07 +03:00

30 lines
1 KiB
TypeScript

import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { sorter } from "../../../utils";
import { remindersCmd } from "../types";
import { clearUpcomingReminder } from "../../../data/loops/upcomingRemindersLoop";
export const RemindersDeleteCmd = remindersCmd({
trigger: ["reminders delete", "reminders d"],
permission: "can_use",
signature: {
num: ct.number(),
},
async run({ message: msg, args, pluginData }) {
const reminders = await pluginData.state.reminders.getRemindersByUserId(msg.author.id);
reminders.sort(sorter("remind_at"));
if (args.num > reminders.length || args.num <= 0) {
sendErrorMessage(pluginData, msg.channel, "Unknown reminder");
return;
}
const toDelete = reminders[args.num - 1];
clearUpcomingReminder(toDelete);
await pluginData.state.reminders.delete(toDelete.id);
sendSuccessMessage(pluginData, msg.channel, "Reminder deleted");
},
});