From 94a2965e8e60110d7811472352512d8a8474183f Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Mon, 16 Dec 2024 18:59:52 +0000 Subject: [PATCH] WIP: Start of creating autokick timer --- src/client/client.ts | 11 ++++++++++- src/timers/AutoKick.ts | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/timers/AutoKick.ts diff --git a/src/client/client.ts b/src/client/client.ts index b51ccda..563a007 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -12,11 +12,14 @@ import ButtonEventItem from "../contracts/ButtonEventItem"; import { ButtonEvent } from "../type/buttonEvent"; import CacheHelper from "../helpers/CacheHelper"; import TimerHelper from "../helpers/TimerHelper"; +import AutoKick from "../timers/AutoKick"; export class CoreClient extends Client { private static _commandItems: ICommandItem[]; private static _eventItems: IEventItem[]; private static _buttonEvents: ButtonEventItem[]; + private static _baseClient: Client; + private _events: Events; private _util: Util; @@ -34,6 +37,10 @@ export class CoreClient extends Client { return this._buttonEvents; } + public static get baseClient(): Client { + return this._baseClient; + } + constructor(intents: number[], partials: Partials[]) { super({ intents: intents, partials: partials }); dotenv.config(); @@ -57,7 +64,7 @@ export class CoreClient extends Client { .then(() => { console.log("Data Source Initialized"); - // this.timerHelper.AddTimer + this._timerHelper.AddTimer("*/5 * * * *", "Europe/London", AutoKick, true); }) .catch((err) => console.error("Error Initialising Data Source", err)); @@ -72,6 +79,8 @@ export class CoreClient extends Client { this._util.loadEvents(this, CoreClient._eventItems); this._util.loadSlashCommands(this); + + CoreClient._baseClient = this; } public static RegisterCommand(name: string, command: Command, serverId?: string) { diff --git a/src/timers/AutoKick.ts b/src/timers/AutoKick.ts new file mode 100644 index 0000000..42a9e93 --- /dev/null +++ b/src/timers/AutoKick.ts @@ -0,0 +1,17 @@ +import {CoreClient} from "../client/client"; +import AutoKickConfig from "../database/entities/AutoKickConfig"; + +export default async function AutoKick() { + const client = CoreClient.baseClient; + const autoKickConfigs = await AutoKickConfig.FetchAll(AutoKickConfig); + + for (let config of autoKickConfigs) { + const guild = client.guilds.cache.find(x => x.id == config.ServerId) || client.guilds.fetch(config.ServerId); + + if (!guild) { + continue; + } + + console.log(typeof guild); + } +}