diff --git a/src/client/client.ts b/src/client/client.ts index f6568e4..59fb946 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -65,7 +65,7 @@ export class CoreClient extends Client { .then(() => { console.log("Data Source Initialized"); - this._timerHelper.AddTimer("*/5 * * * *", "Europe/London", AutoKick, true); + this._timerHelper.AddTimer("0 * * * *", "Europe/London", AutoKick, true); this._timerHelper.StartAllTimers(); }) diff --git a/src/constants/EmbedColours.ts b/src/constants/EmbedColours.ts index 023c77a..dd84b94 100644 --- a/src/constants/EmbedColours.ts +++ b/src/constants/EmbedColours.ts @@ -1,3 +1,5 @@ export default class EmbedColours { public static readonly Ok = 0x3050ba; + public static readonly Warning = 0xffbf00; + public static readonly Danger = 0xd2042d; } \ No newline at end of file diff --git a/src/timers/AutoKick.ts b/src/timers/AutoKick.ts index 8158519..a98aee8 100644 --- a/src/timers/AutoKick.ts +++ b/src/timers/AutoKick.ts @@ -1,5 +1,7 @@ +import { EmbedBuilder } from "discord.js"; import {CoreClient} from "../client/client"; import AutoKickConfig from "../database/entities/AutoKickConfig"; +import EmbedColours from "../constants/EmbedColours"; export default async function AutoKick() { const client = CoreClient.baseClient; @@ -31,7 +33,65 @@ export default async function AutoKick() { const now = new Date(); if (whenToKick < now) { - await member.kick("Auto Kicked"); + // await member.kick("Auto Kicked"); + console.log("Kicked"); + + if (config.NoticeChannelId) { + const channel = guild.channels.cache.find(x => x.id == config.NoticeChannelId) || await guild.channels.fetch(config.NoticeChannelId); + + if (!channel?.isSendable()) { + continue; + } + + const embed = new EmbedBuilder() + .setTitle("Auto Kicked User") + .setColor(EmbedColours.Danger) + .setThumbnail(member.avatarURL()) + .addFields([ + { + name: "User", + value: `<@${member.user.id}> \`${member.user.username}\``, + inline: true, + }, + ]); + + await channel.send({ + embeds: [ embed ], + }); + } + } else if (config.NoticeChannelId && config.NoticeTime) { + const whenToNotice = new Date(whenToKick.getMilliseconds() - config.NoticeTime); + + const channel = guild.channels.cache.find(x => x.id == config.NoticeChannelId) || await guild.channels.fetch(config.NoticeChannelId); + + if (!channel?.isSendable()) { + continue; + } + + if (now.getMonth() == whenToNotice.getMonth() + && now.getDate() == whenToNotice.getDate() + && now.getHours() == whenToNotice.getHours()) { + const embed = new EmbedBuilder() + .setTitle("Auto Kick Notice") + .setColor(EmbedColours.Warning) + .setThumbnail(member.avatarURL()) + .addFields([ + { + name: "User", + value: `<@${member.user.id}> \`${member.user.username}\``, + inline: true, + }, + { + name: "When To Kick", + value: ``, + inline: true, + }, + ]); + + await channel.send({ + embeds: [ embed ], + }); + } } } }