Create helper class
This commit is contained in:
parent
bc3c16bdcb
commit
2b4ae91584
1 changed files with 25 additions and 0 deletions
25
src/helpers/AutoKickHelper.ts
Normal file
25
src/helpers/AutoKickHelper.ts
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue