From afafe246a858249bf3dc9b4da2a8f0215140a50d Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Sat, 21 Dec 2024 14:24:38 +0000 Subject: [PATCH] WIP: Add to the timer the kick functionality --- .env.example | 6 ++++-- src/client/client.ts | 7 ++++--- src/timers/AutoKick.ts | 27 ++++++++++++++++++++++++--- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/.env.example b/.env.example index 44b071b..e2591d0 100644 --- a/.env.example +++ b/.env.example @@ -7,7 +7,7 @@ # any secret values. BOT_TOKEN= -BOT_VER=3.2.3 +BOT_VER=3.2.4 BOT_AUTHOR=Vylpes BOT_OWNERID=147392775707426816 BOT_CLIENTID=682942374040961060 @@ -23,4 +23,6 @@ DB_NAME=vylbot DB_AUTH_USER=dev DB_AUTH_PASS=dev DB_SYNC=true -DB_LOGGING=true \ No newline at end of file +DB_LOGGING=true +DB_DATA_LOCATION=./.temp/database +DB_ROOT_HOST=0.0.0.0 \ No newline at end of file diff --git a/src/client/client.ts b/src/client/client.ts index 563a007..f6568e4 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -20,7 +20,6 @@ export class CoreClient extends Client { private static _buttonEvents: ButtonEventItem[]; private static _baseClient: Client; - private _events: Events; private _util: Util; private _timerHelper: TimerHelper; @@ -60,11 +59,15 @@ export class CoreClient extends Client { return; } + CoreClient._baseClient = this; + await AppDataSource.initialize() .then(() => { console.log("Data Source Initialized"); this._timerHelper.AddTimer("*/5 * * * *", "Europe/London", AutoKick, true); + + this._timerHelper.StartAllTimers(); }) .catch((err) => console.error("Error Initialising Data Source", err)); @@ -79,8 +82,6 @@ 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 index 42a9e93..8158519 100644 --- a/src/timers/AutoKick.ts +++ b/src/timers/AutoKick.ts @@ -6,12 +6,33 @@ export default async function AutoKick() { 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); - + const guild = client.guilds.cache.find(x => x.id == config.ServerId) || await client.guilds.fetch(config.ServerId); + if (!guild) { continue; } - console.log(typeof guild); + await guild.members.fetch(); + + const role = guild.roles.cache.find(x => x.id == config.RoleId); + + if (!role) { + continue; + } + + for (let memberEntity of role.members) { + const member = memberEntity[1]; + + if (!member.kickable) { + continue; + } + + const whenToKick = new Date(member.joinedTimestamp! + config.KickTime); + const now = new Date(); + + if (whenToKick < now) { + await member.kick("Auto Kicked"); + } + } } }