All checks were successful
Test / build (push) Successful in 13s
- Add command to configure the auto kick function - Added ability to run functions on a cron job - Added a cron job every hour to check if a user has had a role for a configured amount of time and kick them if they have - The function also optionally sends a notice embed at a configured time before the kick #485 Reviewed-on: #502 Reviewed-by: VylpesTester <tester@vylpes.com> Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com>
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import AutoKickConfig from "../database/entities/AutoKickConfig";
|
|
|
|
export default class AutoKickHelper {
|
|
public static async GetSetting(serverId: string): Promise<AutoKickConfig | null> {
|
|
const configs = await AutoKickConfig.FetchAllByServerId(serverId);
|
|
|
|
if (configs.length != 1) {
|
|
return null;
|
|
}
|
|
|
|
return configs[0];
|
|
}
|
|
|
|
public static async SetSetting(serverId: string, roleId: string, kickTime: number, noticeTime?: number, noticeChannelId?: string) {
|
|
const configs = await AutoKickConfig.FetchAllByServerId(serverId);
|
|
|
|
if (configs.length == 0) {
|
|
const config = new AutoKickConfig(serverId, roleId, kickTime, noticeTime, noticeChannelId);
|
|
await config.Save(AutoKickConfig, config);
|
|
|
|
return;
|
|
}
|
|
|
|
const config = configs[0];
|
|
|
|
config.UpdateBasicDetails(roleId, kickTime, noticeTime, noticeChannelId);
|
|
await config.Save(AutoKickConfig, config);
|
|
}
|
|
|
|
public static async UnsetSetting(serverId: string) {
|
|
const configs = await AutoKickConfig.FetchAllByServerId(serverId);
|
|
|
|
for (let config of configs) {
|
|
await AutoKickConfig.Remove(AutoKickConfig, config);
|
|
}
|
|
}
|
|
}
|