From 2b4ae91584e60df9295cd667399fe77c278a7560 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Fri, 6 Dec 2024 20:27:17 +0000 Subject: [PATCH] Create helper class --- src/helpers/AutoKickHelper.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/helpers/AutoKickHelper.ts diff --git a/src/helpers/AutoKickHelper.ts b/src/helpers/AutoKickHelper.ts new file mode 100644 index 0000000..7c3e2aa --- /dev/null +++ b/src/helpers/AutoKickHelper.ts @@ -0,0 +1,25 @@ +import AutoKickConfig from "../database/entities/AutoKickConfig"; + +export default class AutoKickHelper { + public static async SetSetting(serverId: string, roleId: string, kickTime: number, noticeTime?: number, noticeChannelId?: string) { + const config = await AutoKickConfig.FetchOneByServerIdAndRoleId(serverId, roleId); + + if (!config) { + const newConfig = new AutoKickConfig(serverId, roleId, kickTime, noticeTime, noticeChannelId); + await newConfig.Save(AutoKickConfig, newConfig); + + return; + } + + config.UpdateBasicDetails(roleId, kickTime, noticeTime, noticeChannelId); + await config.Save(AutoKickConfig, config); + } + + public static async ResetSetting(serverId: string, roleId: string) { + const config = await AutoKickConfig.FetchOneByServerIdAndRoleId(serverId, roleId); + + if (!config) return; + + await AutoKickConfig.Remove(AutoKickConfig, config); + } +}