WIP: Add to the timer the kick functionality
All checks were successful
Test / build (push) Successful in 13s

This commit is contained in:
Ethan Lane 2024-12-21 14:24:38 +00:00
parent 94a2965e8e
commit afafe246a8
3 changed files with 32 additions and 8 deletions

View file

@ -7,7 +7,7 @@
# any secret values. # any secret values.
BOT_TOKEN= BOT_TOKEN=
BOT_VER=3.2.3 BOT_VER=3.2.4
BOT_AUTHOR=Vylpes BOT_AUTHOR=Vylpes
BOT_OWNERID=147392775707426816 BOT_OWNERID=147392775707426816
BOT_CLIENTID=682942374040961060 BOT_CLIENTID=682942374040961060
@ -24,3 +24,5 @@ DB_AUTH_USER=dev
DB_AUTH_PASS=dev DB_AUTH_PASS=dev
DB_SYNC=true DB_SYNC=true
DB_LOGGING=true DB_LOGGING=true
DB_DATA_LOCATION=./.temp/database
DB_ROOT_HOST=0.0.0.0

View file

@ -20,7 +20,6 @@ export class CoreClient extends Client {
private static _buttonEvents: ButtonEventItem[]; private static _buttonEvents: ButtonEventItem[];
private static _baseClient: Client; private static _baseClient: Client;
private _events: Events; private _events: Events;
private _util: Util; private _util: Util;
private _timerHelper: TimerHelper; private _timerHelper: TimerHelper;
@ -60,11 +59,15 @@ export class CoreClient extends Client {
return; return;
} }
CoreClient._baseClient = this;
await AppDataSource.initialize() await AppDataSource.initialize()
.then(() => { .then(() => {
console.log("Data Source Initialized"); console.log("Data Source Initialized");
this._timerHelper.AddTimer("*/5 * * * *", "Europe/London", AutoKick, true); this._timerHelper.AddTimer("*/5 * * * *", "Europe/London", AutoKick, true);
this._timerHelper.StartAllTimers();
}) })
.catch((err) => console.error("Error Initialising Data Source", err)); .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.loadEvents(this, CoreClient._eventItems);
this._util.loadSlashCommands(this); this._util.loadSlashCommands(this);
CoreClient._baseClient = this;
} }
public static RegisterCommand(name: string, command: Command, serverId?: string) { public static RegisterCommand(name: string, command: Command, serverId?: string) {

View file

@ -6,12 +6,33 @@ export default async function AutoKick() {
const autoKickConfigs = await AutoKickConfig.FetchAll(AutoKickConfig); const autoKickConfigs = await AutoKickConfig.FetchAll(AutoKickConfig);
for (let config of autoKickConfigs) { 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) { if (!guild) {
continue; 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");
}
}
} }
} }