diff --git a/package-lock.json b/package-lock.json index 54614bc..6d144ca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,6 @@ "@types/uuid": "^9.0.0", "body-parser": "^1.20.2", "clone-deep": "^4.0.1", - "cron": "^3.1.7", "discord.js": "^14.3.0", "dotenv": "^16.0.0", "express": "^4.18.2", @@ -1896,11 +1895,6 @@ "@types/node": "*" } }, - "node_modules/@types/luxon": { - "version": "3.4.2", - "resolved": "https://registry.npmjs.org/@types/luxon/-/luxon-3.4.2.tgz", - "integrity": "sha512-TifLZlFudklWlMBfhubvgqTXRzLDI5pCbGa4P8a3wPyUQSW+1xQ5eDsreP9DWHX3tjq1ke96uYG/nwundroWcA==" - }, "node_modules/@types/mime": { "version": "3.0.4", "license": "MIT" @@ -3847,15 +3841,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/cron": { - "version": "3.1.7", - "resolved": "https://registry.npmjs.org/cron/-/cron-3.1.7.tgz", - "integrity": "sha512-tlBg7ARsAMQLzgwqVxy8AZl/qlTc5nibqYwtNGoCrd+cV+ugI+tvZC1oT/8dFH8W455YrywGykx/KMmAqOr7Jw==", - "dependencies": { - "@types/luxon": "~3.4.0", - "luxon": "~3.4.0" - } - }, "node_modules/cross-spawn": { "version": "7.0.3", "license": "MIT", @@ -7715,14 +7700,6 @@ "node": ">=10" } }, - "node_modules/luxon": { - "version": "3.4.4", - "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.4.4.tgz", - "integrity": "sha512-zobTr7akeGHnv7eBOXcRgMeCP6+uyYsczwmeRCauvpvaAltgNyTbLH/+VaEAPUeWBT+1GuNmz4wC/6jtQzbbVA==", - "engines": { - "node": ">=12" - } - }, "node_modules/magic-bytes.js": { "version": "1.6.0", "license": "MIT" diff --git a/package.json b/package.json index 004cfb8..178f288 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "@types/uuid": "^9.0.0", "body-parser": "^1.20.2", "clone-deep": "^4.0.1", - "cron": "^3.1.7", "discord.js": "^14.3.0", "dotenv": "^16.0.0", "express": "^4.18.2", diff --git a/src/bot.ts b/src/bot.ts index e5e25a3..87008c5 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -37,6 +37,7 @@ const client = new CoreClient([ ]); Registry.RegisterCommands(); +Registry.RegisterEvents(); Registry.RegisterButtonEvents(); if (!existsSync(`${process.env.DATA_DIR}/cards`) && process.env.GDRIVESYNC_AUTO && process.env.GDRIVESYNC_AUTO == "true") { diff --git a/src/client/client.ts b/src/client/client.ts index 2dd9a29..c694950 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -14,8 +14,6 @@ import Webhooks from "../webhooks"; import CardMetadataFunction from "../Functions/CardMetadataFunction"; import { SeriesMetadata } from "../contracts/SeriesMetadata"; import AppLogger from "./appLogger"; -import TimerHelper from "../helpers/TimerHelper"; -import GiveCurrency from "../timers/GiveCurrency"; export class CoreClient extends Client { private static _commandItems: ICommandItem[]; @@ -25,7 +23,6 @@ export class CoreClient extends Client { private _events: Events; private _util: Util; private _webhooks: Webhooks; - private _timerHelper: TimerHelper; public static ClaimId: string; public static Environment: Environment; @@ -62,7 +59,6 @@ export class CoreClient extends Client { this._events = new Events(); this._util = new Util(); this._webhooks = new Webhooks(); - this._timerHelper = new TimerHelper(); AppLogger.LogInfo("Client", `Environment: ${CoreClient.Environment}`); @@ -76,12 +72,7 @@ export class CoreClient extends Client { } await AppDataSource.initialize() - .then(() => { - AppLogger.LogInfo("Client", "App Data Source Initialised"); - - const timerId = this._timerHelper.AddTimer("*/30 * * * * *", "Europe/London", GiveCurrency, false); - this._timerHelper.StartTimer(timerId); - }) + .then(() => AppLogger.LogInfo("Client", "App Data Source Initialised")) .catch(err => { AppLogger.LogError("Client", "App Data Source Initialisation Failed"); AppLogger.LogError("Client", err); diff --git a/src/contracts/AppBaseEntity.ts b/src/contracts/AppBaseEntity.ts index 3eb9684..b9ca565 100644 --- a/src/contracts/AppBaseEntity.ts +++ b/src/contracts/AppBaseEntity.ts @@ -27,12 +27,6 @@ export default class AppBaseEntity { await repository.save(entity); } - public static async SaveAll(target: EntityTarget, entities: DeepPartial[]): Promise { - const repository = AppDataSource.getRepository(target); - - await repository.save(entities); - } - public static async Remove(target: EntityTarget, entity: T): Promise { const repository = AppDataSource.getRepository(target); diff --git a/src/database/entities/app/User.ts b/src/database/entities/app/User.ts index a909552..4c5798d 100644 --- a/src/database/entities/app/User.ts +++ b/src/database/entities/app/User.ts @@ -13,6 +13,10 @@ export default class User extends AppBaseEntity { @Column() Currency: number; + public UpdateCurrency(currency: number) { + this.Currency = currency; + } + public AddCurrency(amount: number) { this.Currency += amount; } diff --git a/src/helpers/TimerHelper.ts b/src/helpers/TimerHelper.ts deleted file mode 100644 index 535a6a7..0000000 --- a/src/helpers/TimerHelper.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { CronJob } from "cron"; -import { v4 } from "uuid"; -import { Primitive } from "../type/primitive"; - -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); - } - } -} \ No newline at end of file diff --git a/src/registry.ts b/src/registry.ts index 15202c5..8e6a713 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -44,6 +44,10 @@ export default class Registry { CoreClient.RegisterCommand("droprarity", new Droprarity(), Environment.Test); } + public static RegisterEvents() { + + } + public static RegisterButtonEvents() { CoreClient.RegisterButtonEvent("claim", new Claim()); CoreClient.RegisterButtonEvent("inventory", new InventoryButtonEvent()); diff --git a/src/timers/GiveCurrency.ts b/src/timers/GiveCurrency.ts deleted file mode 100644 index ad1a21a..0000000 --- a/src/timers/GiveCurrency.ts +++ /dev/null @@ -1,16 +0,0 @@ -import AppLogger from "../client/appLogger"; -import User from "../database/entities/app/User"; - -export default async function GiveCurrency() { - AppLogger.LogInfo("Timers/GiveCurrency", "Giving currency to every known user"); - - const users = await User.FetchAll(User); - - for (const user of users) { - user.AddCurrency(5); - } - - User.SaveAll(User, users); - - AppLogger.LogInfo("Timers/GiveCurrency", `Successfully gave +5 currency to ${users.length} users`); -} \ No newline at end of file diff --git a/src/type/primitive.ts b/src/type/primitive.ts deleted file mode 100644 index b1e143b..0000000 --- a/src/type/primitive.ts +++ /dev/null @@ -1 +0,0 @@ -export type Primitive = string | number | boolean; \ No newline at end of file