@elara-services/packages 4.5.1 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -191,5 +191,15 @@ declare module "@elara-services/packages" {
191
191
  static validate(value: string): boolean;
192
192
  static parse(value: string): number | null;
193
193
  static determineTimeType(str: string): number;
194
+ };
195
+
196
+ export class Tasks extends null {
197
+ static create(options: {
198
+ id: string;
199
+ time: string;
200
+ shouldCancel?: boolean
201
+ }, run: Function): void;
202
+
203
+ static delete(id: string): void;
194
204
  }
195
205
  }
package/index.js CHANGED
@@ -7,4 +7,5 @@ exports.Languages = require("./packages/languages");
7
7
  exports.SlashBuilder = require("./packages/SlashBuilder");
8
8
  exports.Interactions = require("./packages/Interactions");
9
9
  exports.fetch = require("./packages/fetch");
10
- exports.Duration = require("./packages/duration");
10
+ exports.Duration = require("./packages/duration");
11
+ exports.Tasks = require("./packages/Tasks");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elara-services/packages",
3
- "version": "4.5.1",
3
+ "version": "4.6.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "./index.d.ts",
@@ -0,0 +1,22 @@
1
+ let nodeSchedule;
2
+
3
+ try {
4
+ nodeSchedule = require("node-schedule");
5
+ } catch { };
6
+
7
+ module.exports = class Tasks extends null {
8
+ static create({ id = "", time = "", shouldCancel = true } = {}, run) {
9
+ if (!nodeSchedule) return `[Tasks:Create:ERROR]: I was unable to locate the 'node-schedule' package!`;
10
+ if (!id || !time || !run) return `[Tasks:Create:ERROR]: You didn't provide a valid ID, Time or Run function`;
11
+ if (nodeSchedule.scheduledJobs[id]) return `[Tasks:Create:ERROR]: Found (${id}) already in the scheduledJobs object.`;
12
+ return nodeSchedule.scheduleJob(id, time, () => {
13
+ run();
14
+ if (shouldCancel) return nodeSchedule.cancelJob(id);
15
+ });
16
+ };
17
+
18
+ static delete(id) {
19
+ if (!nodeSchedule) return null;
20
+ return nodeSchedule.cancelJob(id);
21
+ };
22
+ };