diff --git a/package.json b/package.json index 27b06a3..c5af404 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ "@discordjs/rest": "^2.0.0", "@types/jest": "^29.0.0", "@types/uuid": "^9.0.0", - "cron": "^3.3.1", "discord.js": "^14.3.0", "dotenv": "^16.0.0", "emoji-regex": "^10.0.0", diff --git a/src/client/client.ts b/src/client/client.ts index 563a007..c1ce5da 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -1,5 +1,6 @@ import { Client, Partials } from "discord.js"; import * as dotenv from "dotenv"; +import { createConnection } from "typeorm"; import { EventType } from "../constants/EventType"; import ICommandItem from "../contracts/ICommandItem"; import IEventItem from "../contracts/IEventItem"; @@ -11,19 +12,14 @@ import AppDataSource from "../database/dataSources/appDataSource"; 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; - private _timerHelper: TimerHelper; public static get commandItems(): ICommandItem[] { return this._commandItems; @@ -37,10 +33,6 @@ 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(); @@ -51,7 +43,6 @@ export class CoreClient extends Client { this._events = new Events(); this._util = new Util(); - this._timerHelper = new TimerHelper(); } public async start() { @@ -61,11 +52,7 @@ export class CoreClient extends Client { } await AppDataSource.initialize() - .then(() => { - console.log("Data Source Initialized"); - - this._timerHelper.AddTimer("*/5 * * * *", "Europe/London", AutoKick, true); - }) + .then(() => console.log("Data Source Initialized")) .catch((err) => console.error("Error Initialising Data Source", err)); super.on("interactionCreate", this._events.onInteractionCreate); @@ -79,8 +66,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/helpers/TimerHelper.ts b/src/helpers/TimerHelper.ts deleted file mode 100644 index 3cc4246..0000000 --- a/src/helpers/TimerHelper.ts +++ /dev/null @@ -1,81 +0,0 @@ -import {CronJob} from "cron"; -import {primitive} from "../type/primitive"; -import {v4} from "uuid"; - -interface Timer { - id: string; - job: CronJob; - context: Map; - onTick: ((context: Map) => void) | ((context: Map) => Promise); - runOnStart: boolean; -} - -export default class TimerHelper { - private _timers: Timer[]; - - constructor() { - this._timers = []; - } - - public AddTimer( - cronTime: string, - timeZone: string, - onTick: ((context: Map) => void) | ((context: Map) => Promise), - runOnStart: boolean = false): string { - const context = new Map(); - - const job = new CronJob( - cronTime, - () => { - onTick(context); - }, - null, - false, - timeZone, - ); - - const id = v4(); - - this._timers.push({ - id, - job, - context, - onTick, - runOnStart, - }); - - return id; - } - - public StartAllTimers() { - this._timers.forEach(timer => this.StartJob(timer)); - } - - public StopAllTimers() { - this._timers.forEach(timer => timer.job.stop()); - } - - public StartTimer(id: string) { - const timer = this._timers.find(x => x.id == id); - - if (!timer) return; - - this.StartJob(timer); - } - - public StopTimer(id: string) { - const timer = this._timers.find(x => x.id == id); - - if (!timer) return; - - timer.job.stop(); - } - - private StartJob(timer: Timer) { - timer.job.start(); - - if (timer.runOnStart) { - timer.onTick(timer.context); - } - } -} diff --git a/src/timers/AutoKick.ts b/src/timers/AutoKick.ts deleted file mode 100644 index 42a9e93..0000000 --- a/src/timers/AutoKick.ts +++ /dev/null @@ -1,17 +0,0 @@ -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); - } -} diff --git a/src/type/primitive.ts b/src/type/primitive.ts deleted file mode 100644 index 9093737..0000000 --- a/src/type/primitive.ts +++ /dev/null @@ -1 +0,0 @@ -export type primitive = string | number | boolean; diff --git a/yarn.lock b/yarn.lock index 24feeb5..ced241e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -788,11 +788,6 @@ expect "^29.0.0" pretty-format "^29.0.0" -"@types/luxon@~3.4.0": - version "3.4.2" - resolved "https://registry.yarnpkg.com/@types/luxon/-/luxon-3.4.2.tgz#e4fc7214a420173cea47739c33cdf10874694db7" - integrity sha512-TifLZlFudklWlMBfhubvgqTXRzLDI5pCbGa4P8a3wPyUQSW+1xQ5eDsreP9DWHX3tjq1ke96uYG/nwundroWcA== - "@types/node@*": version "22.7.5" resolved "https://registry.npmjs.org/@types/node/-/node-22.7.5.tgz" @@ -1463,14 +1458,6 @@ create-jest@^29.7.0: jest-util "^29.7.0" prompts "^2.0.1" -cron@^3.3.1: - version "3.3.1" - resolved "https://registry.yarnpkg.com/cron/-/cron-3.3.1.tgz#03c56b4a3ad52606160adfba1fab932c53838807" - integrity sha512-KpvuzJEbeTMTfLsXhUuDfsFYr8s5roUlLKb4fa68GszWrA4783C7q6m9yj4vyc6neyD/V9e0YiADSX2c+yRDXg== - dependencies: - "@types/luxon" "~3.4.0" - luxon "~3.5.0" - cross-spawn@^7.0.0, cross-spawn@^7.0.3: version "7.0.3" resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz" @@ -3089,11 +3076,6 @@ lru-cache@^5.1.1: dependencies: yallist "^3.0.2" -luxon@~3.5.0: - version "3.5.0" - resolved "https://registry.yarnpkg.com/luxon/-/luxon-3.5.0.tgz#6b6f65c5cd1d61d1fd19dbf07ee87a50bf4b8e20" - integrity sha512-rh+Zjr6DNfUYR3bPwJEnuwDdqMbxZW7LOQfUN4B54+Cl+0o5zaU9RJ6bcidfDtC1cWCZXQ+nvX8bf6bAji37QQ== - magic-bytes.js@^1.10.0: version "1.10.0" resolved "https://registry.npmjs.org/magic-bytes.js/-/magic-bytes.js-1.10.0.tgz"