@kingsworld/plugin-cron 2.0.4-next.dd192a4 → 2.1.0-next.47cb7ef

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.
@@ -6,7 +6,7 @@ var CronTaskStore_cjs = require('./lib/structures/CronTaskStore.cjs');
6
6
  var CronTaskTypes_cjs = require('./lib/types/CronTaskTypes.cjs');
7
7
 
8
8
  // src/index.ts
9
- var version = "2.0.4-next.dd192a4";
9
+ var version = "2.1.0-next.47cb7ef";
10
10
 
11
11
  exports.version = version;
12
12
  Object.keys(CronTaskHandler_cjs).forEach(function (k) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;AA+BO,IAAM,OAAkB,GAAA","file":"index.cjs","sourcesContent":["import type { CronTaskStore } from './lib/structures/CronTaskStore';\nimport type { CronTaskHandler } from './lib/CronTaskHandler';\nimport type { CronTaskHandlerOptions } from './lib/types/CronTaskTypes';\n\nexport * from './lib/CronTaskHandler';\nexport * from './lib/structures/CronTask';\nexport * from './lib/structures/CronTaskStore';\nexport * from './lib/types/CronTaskTypes';\n\ndeclare module '@sapphire/pieces' {\n\tinterface Container {\n\t\tcron: CronTaskHandler;\n\t}\n\n\tinterface StoreRegistryEntries {\n\t\t'cron-tasks': CronTaskStore;\n\t}\n}\n\ndeclare module 'discord.js' {\n\texport interface ClientOptions {\n\t\tcron?: Partial<CronTaskHandlerOptions>;\n\t}\n}\n\n/**\n * The [@kingsworld/plugin-cron](https://github.com/Kings-World/sapphire-plugins/tree/main/packages/cron) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\nexport const version: string = '2.0.4-next.dd192a4';\n"]}
1
+ {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;AA+BO,IAAM,OAAkB,GAAA","file":"index.cjs","sourcesContent":["import type { CronTaskStore } from './lib/structures/CronTaskStore';\nimport type { CronTaskHandler } from './lib/CronTaskHandler';\nimport type { CronTaskHandlerOptions } from './lib/types/CronTaskTypes';\n\nexport * from './lib/CronTaskHandler';\nexport * from './lib/structures/CronTask';\nexport * from './lib/structures/CronTaskStore';\nexport * from './lib/types/CronTaskTypes';\n\ndeclare module '@sapphire/pieces' {\n\tinterface Container {\n\t\tcron: CronTaskHandler;\n\t}\n\n\tinterface StoreRegistryEntries {\n\t\t'cron-tasks': CronTaskStore;\n\t}\n}\n\ndeclare module 'discord.js' {\n\texport interface ClientOptions {\n\t\tcron?: Partial<CronTaskHandlerOptions>;\n\t}\n}\n\n/**\n * The [@kingsworld/plugin-cron](https://github.com/Kings-World/sapphire-plugins/tree/main/packages/cron) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\nexport const version: string = '2.1.0-next.47cb7ef';\n"]}
@@ -20,6 +20,19 @@ interface CronTaskHandlerOptions {
20
20
  disableSentry: boolean;
21
21
  }
22
22
  type CronJobOptions = Omit<CronJobParams<null, CronTask>, 'onTick' | 'onComplete' | 'start' | 'context' | 'utcOffset'>;
23
+ /**
24
+ * The @types/luxon package doesn't seem to be up-to-date with luxon.
25
+ * Therefore, I have to manually add the ianaName getter to the FixedOffsetZone class.
26
+ * The code can be found here: https://github.com/moment/luxon/blob/3e9983cd0680fdf7836fcee638d34e3edc682380/src/zones/fixedOffsetZone.js#L80C7-L80C15
27
+ */
28
+ declare module 'luxon' {
29
+ interface FixedOffsetZone {
30
+ /**
31
+ * The IANA name of this zone, i.e. `Etc/UTC` or `Etc/GMT+/-nn`
32
+ */
33
+ get ianaName(): string;
34
+ }
35
+ }
23
36
 
24
37
  /**
25
38
  * @example
@@ -114,6 +127,14 @@ declare class CronTaskStore extends Store<CronTask, 'cron-tasks'> {
114
127
  * @returns void
115
128
  */
116
129
  clear(): void;
130
+ /**
131
+ * Formats a Luxon-compatible timezone string into a TZ timezone string.
132
+ * This is required because Sentry requires time zones to be in TZ format.
133
+ * @param timezone The Luxon-compatible timezone to format.
134
+ * @returns The formatted TZ timezone.
135
+ * @private
136
+ */
137
+ private formatLuxonZone;
117
138
  }
118
139
 
119
140
  declare class CronTaskHandler {
@@ -3,6 +3,7 @@
3
3
  var pieces = require('@sapphire/pieces');
4
4
  var cron = require('cron');
5
5
  var CronTask_cjs = require('./CronTask.cjs');
6
+ var luxon = require('luxon');
6
7
 
7
8
  var __defProp = Object.defineProperty;
8
9
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -45,7 +46,7 @@ var _CronTaskStore = class _CronTaskStore extends pieces.Store {
45
46
  onTick: /* @__PURE__ */ __name(() => void value.run.bind(value)(), "onTick"),
46
47
  start: false,
47
48
  context: value,
48
- timeZone: options.timeZone ?? defaultTimezone
49
+ timeZone: this.formatLuxonZone(options.timeZone ?? defaultTimezone)
49
50
  });
50
51
  } catch (error) {
51
52
  value.error("Encountered an error while creating the cron job", error);
@@ -68,6 +69,19 @@ var _CronTaskStore = class _CronTaskStore extends pieces.Store {
68
69
  this.stopAll();
69
70
  return super.clear();
70
71
  }
72
+ /**
73
+ * Formats a Luxon-compatible timezone string into a TZ timezone string.
74
+ * This is required because Sentry requires time zones to be in TZ format.
75
+ * @param timezone The Luxon-compatible timezone to format.
76
+ * @returns The formatted TZ timezone.
77
+ * @private
78
+ */
79
+ formatLuxonZone(timezone) {
80
+ const zone = luxon.Info.normalizeZone(timezone);
81
+ if (!zone.isValid) return luxon.DateTime.local().zoneName;
82
+ if (zone instanceof luxon.FixedOffsetZone) return zone.ianaName;
83
+ return zone.name;
84
+ }
71
85
  };
72
86
  __name(_CronTaskStore, "CronTaskStore");
73
87
  var CronTaskStore = _CronTaskStore;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/CronTaskStore.ts"],"names":["Store","CronTask","CronJob"],"mappings":";;;;;;;;AAIO,IAAM,cAAA,GAAN,MAAM,c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AAA,CAAA,GAAA,GAAM,QAAQ,IAAK,CAAA;AAAA,QACxB,GAAG,OAAA;AAAA,QACH,MAAA,+BAAc,KAAK,KAAA,CAAM,IAAI,IAAK,CAAA,KAAK,GAA/B,EAAA,QAAA,CAAA;AAAA,QACR,KAAO,EAAA,KAAA;AAAA,QACP,OAAS,EAAA,KAAA;AAAA,QACT,QAAA,EAAU,QAAQ,QAAY,IAAA,eAAA;AAAA,OAC9B,CAAA,CAAA;AAAA,aACO,KAAO,EAAA;AACf,MAAM,KAAA,CAAA,KAAA,CAAM,oDAAoD,KAAK,CAAA,CAAA;AACrE,MAAA,KAAK,MAAM,MAAO,EAAA,CAAA;AAAA,KACnB;AAEA,IAAO,OAAA,KAAA,CAAM,GAAI,CAAA,GAAA,EAAK,KAAK,CAAA,CAAA;AAAA,GAC5B;AAAA,EAEgB,OAAO,GAAa,EAAA;AACnC,IAAM,MAAA,IAAA,GAAO,IAAK,CAAA,GAAA,CAAI,GAAG,CAAA,CAAA;AACzB,IAAI,IAAA,IAAA,EAAM,IAAI,OAAS,EAAA;AACtB,MAAA,IAAA,CAAK,IAAI,IAAK,EAAA,CAAA;AAAA,KACf;AAEA,IAAO,OAAA,KAAA,CAAM,OAAO,GAAG,CAAA,CAAA;AAAA,GACxB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMgB,KAAQ,GAAA;AACvB,IAAA,IAAA,CAAK,OAAQ,EAAA,CAAA;AACb,IAAA,OAAO,MAAM,KAAM,EAAA,CAAA;AAAA,GACpB;AACD,CAAA,CAAA;AAzEiE,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA,CAAA;AAA1D,IAAM,aAAN,GAAA","file":"CronTaskStore.cjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { CronJob } from 'cron';\nimport { CronTask } from './CronTask';\n\nexport class CronTaskStore extends Store<CronTask, 'cron-tasks'> {\n\tpublic constructor() {\n\t\tsuper(CronTask, { name: 'cron-tasks' });\n\t}\n\n\t/**\n\t * Loops over all tasks and starts those that are enabled.\n\t * This gets called automatically when the Client is ready.\n\t * @returns CronTaskStore\n\t */\n\tpublic startAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled) continue;\n\t\t\ttask.job.start();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [START] Started all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Loops over all tasks and stops those that are running.\n\t * @returns CronTaskStore\n\t */\n\tpublic stopAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.job.running) continue;\n\t\t\ttask.job.stop();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [STOP] Stopped all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\tpublic override set(key: string, value: CronTask): this {\n\t\tconst { options } = value;\n\n\t\tconst { sentry, defaultTimezone } = this.container.cron;\n\t\tconst cronJob = sentry ? sentry.cron.instrumentCron(CronJob, key) : CronJob;\n\n\t\ttry {\n\t\t\tvalue.job = cronJob.from({\n\t\t\t\t...options,\n\t\t\t\tonTick: () => void value.run.bind(value)(),\n\t\t\t\tstart: false,\n\t\t\t\tcontext: value,\n\t\t\t\ttimeZone: options.timeZone ?? defaultTimezone\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tvalue.error('Encountered an error while creating the cron job', error);\n\t\t\tvoid value.unload();\n\t\t}\n\n\t\treturn super.set(key, value);\n\t}\n\n\tpublic override delete(key: string) {\n\t\tconst task = this.get(key);\n\t\tif (task?.job.running) {\n\t\t\ttask.job.stop();\n\t\t}\n\n\t\treturn super.delete(key);\n\t}\n\n\t/**\n\t * Stops all running cron jobs and clears the store.\n\t * @returns void\n\t */\n\tpublic override clear() {\n\t\tthis.stopAll();\n\t\treturn super.clear();\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/CronTaskStore.ts"],"names":["Store","CronTask","CronJob","Info","DateTime","FixedOffsetZone"],"mappings":";;;;;;;;;AAKO,IAAM,cAAA,GAAN,M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IAAA,IAAA,YAAgBC,qBAAiB,EAAA,OAAO,IAAK,CAAA,QAAA,CAAA;AAGjD,IAAA,OAAO,IAAK,CAAA,IAAA,CAAA;AAAA,GACb;AACD,CAAA,CAAA;AA7FiE,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA,CAAA;AAA1D,IAAM,aAAN,GAAA","file":"CronTaskStore.cjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { CronJob } from 'cron';\nimport { CronTask } from './CronTask';\nimport { Info, DateTime, FixedOffsetZone, type Zone } from 'luxon';\n\nexport class CronTaskStore extends Store<CronTask, 'cron-tasks'> {\n\tpublic constructor() {\n\t\tsuper(CronTask, { name: 'cron-tasks' });\n\t}\n\n\t/**\n\t * Loops over all tasks and starts those that are enabled.\n\t * This gets called automatically when the Client is ready.\n\t * @returns CronTaskStore\n\t */\n\tpublic startAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled) continue;\n\t\t\ttask.job.start();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [START] Started all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Loops over all tasks and stops those that are running.\n\t * @returns CronTaskStore\n\t */\n\tpublic stopAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.job.running) continue;\n\t\t\ttask.job.stop();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [STOP] Stopped all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\tpublic override set(key: string, value: CronTask): this {\n\t\tconst { options } = value;\n\n\t\tconst { sentry, defaultTimezone } = this.container.cron;\n\t\tconst cronJob = sentry ? sentry.cron.instrumentCron(CronJob, key) : CronJob;\n\n\t\ttry {\n\t\t\tvalue.job = cronJob.from({\n\t\t\t\t...options,\n\t\t\t\tonTick: () => void value.run.bind(value)(),\n\t\t\t\tstart: false,\n\t\t\t\tcontext: value,\n\t\t\t\ttimeZone: this.formatLuxonZone(options.timeZone ?? defaultTimezone)\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tvalue.error('Encountered an error while creating the cron job', error);\n\t\t\tvoid value.unload();\n\t\t}\n\n\t\treturn super.set(key, value);\n\t}\n\n\tpublic override delete(key: string) {\n\t\tconst task = this.get(key);\n\t\tif (task?.job.running) {\n\t\t\ttask.job.stop();\n\t\t}\n\n\t\treturn super.delete(key);\n\t}\n\n\t/**\n\t * Stops all running cron jobs and clears the store.\n\t * @returns void\n\t */\n\tpublic override clear() {\n\t\tthis.stopAll();\n\t\treturn super.clear();\n\t}\n\n\t/**\n\t * Formats a Luxon-compatible timezone string into a TZ timezone string.\n\t * This is required because Sentry requires time zones to be in TZ format.\n\t * @param timezone The Luxon-compatible timezone to format.\n\t * @returns The formatted TZ timezone.\n\t * @private\n\t */\n\tprivate formatLuxonZone(timezone?: string | Zone | number) {\n\t\tconst zone = Info.normalizeZone(timezone);\n\n\t\t// If the zone is invalid, return the system zone\n\t\tif (!zone.isValid) return DateTime.local().zoneName;\n\n\t\t// If the zone is a fixed offset zone, return the IANA name\n\t\tif (zone instanceof FixedOffsetZone) return zone.ianaName;\n\n\t\t// Otherwise, return the zone name\n\t\treturn zone.name;\n\t}\n}\n"]}
@@ -20,6 +20,19 @@ interface CronTaskHandlerOptions {
20
20
  disableSentry: boolean;
21
21
  }
22
22
  type CronJobOptions = Omit<CronJobParams<null, CronTask>, 'onTick' | 'onComplete' | 'start' | 'context' | 'utcOffset'>;
23
+ /**
24
+ * The @types/luxon package doesn't seem to be up-to-date with luxon.
25
+ * Therefore, I have to manually add the ianaName getter to the FixedOffsetZone class.
26
+ * The code can be found here: https://github.com/moment/luxon/blob/3e9983cd0680fdf7836fcee638d34e3edc682380/src/zones/fixedOffsetZone.js#L80C7-L80C15
27
+ */
28
+ declare module 'luxon' {
29
+ interface FixedOffsetZone {
30
+ /**
31
+ * The IANA name of this zone, i.e. `Etc/UTC` or `Etc/GMT+/-nn`
32
+ */
33
+ get ianaName(): string;
34
+ }
35
+ }
23
36
 
24
37
  /**
25
38
  * @example
@@ -114,6 +127,14 @@ declare class CronTaskStore extends Store<CronTask, 'cron-tasks'> {
114
127
  * @returns void
115
128
  */
116
129
  clear(): void;
130
+ /**
131
+ * Formats a Luxon-compatible timezone string into a TZ timezone string.
132
+ * This is required because Sentry requires time zones to be in TZ format.
133
+ * @param timezone The Luxon-compatible timezone to format.
134
+ * @returns The formatted TZ timezone.
135
+ * @private
136
+ */
137
+ private formatLuxonZone;
117
138
  }
118
139
 
119
140
  declare class CronTaskHandler {
@@ -4,7 +4,7 @@ export * from './lib/structures/CronTask.mjs';
4
4
  export * from './lib/structures/CronTaskStore.mjs';
5
5
  export * from './lib/types/CronTaskTypes.mjs';
6
6
 
7
- var version = "2.0.4-next.dd192a4";
7
+ var version = "2.1.0-next.47cb7ef";
8
8
 
9
9
  export { version };
10
10
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AA+BO,IAAM,OAAkB,GAAA","file":"index.mjs","sourcesContent":["import type { CronTaskStore } from './lib/structures/CronTaskStore';\nimport type { CronTaskHandler } from './lib/CronTaskHandler';\nimport type { CronTaskHandlerOptions } from './lib/types/CronTaskTypes';\n\nexport * from './lib/CronTaskHandler';\nexport * from './lib/structures/CronTask';\nexport * from './lib/structures/CronTaskStore';\nexport * from './lib/types/CronTaskTypes';\n\ndeclare module '@sapphire/pieces' {\n\tinterface Container {\n\t\tcron: CronTaskHandler;\n\t}\n\n\tinterface StoreRegistryEntries {\n\t\t'cron-tasks': CronTaskStore;\n\t}\n}\n\ndeclare module 'discord.js' {\n\texport interface ClientOptions {\n\t\tcron?: Partial<CronTaskHandlerOptions>;\n\t}\n}\n\n/**\n * The [@kingsworld/plugin-cron](https://github.com/Kings-World/sapphire-plugins/tree/main/packages/cron) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\nexport const version: string = '2.0.4-next.dd192a4';\n"]}
1
+ {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AA+BO,IAAM,OAAkB,GAAA","file":"index.mjs","sourcesContent":["import type { CronTaskStore } from './lib/structures/CronTaskStore';\nimport type { CronTaskHandler } from './lib/CronTaskHandler';\nimport type { CronTaskHandlerOptions } from './lib/types/CronTaskTypes';\n\nexport * from './lib/CronTaskHandler';\nexport * from './lib/structures/CronTask';\nexport * from './lib/structures/CronTaskStore';\nexport * from './lib/types/CronTaskTypes';\n\ndeclare module '@sapphire/pieces' {\n\tinterface Container {\n\t\tcron: CronTaskHandler;\n\t}\n\n\tinterface StoreRegistryEntries {\n\t\t'cron-tasks': CronTaskStore;\n\t}\n}\n\ndeclare module 'discord.js' {\n\texport interface ClientOptions {\n\t\tcron?: Partial<CronTaskHandlerOptions>;\n\t}\n}\n\n/**\n * The [@kingsworld/plugin-cron](https://github.com/Kings-World/sapphire-plugins/tree/main/packages/cron) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\nexport const version: string = '2.1.0-next.47cb7ef';\n"]}
@@ -2,6 +2,7 @@ import { __name } from '../../chunk-2JTKI4GS.mjs';
2
2
  import { Store } from '@sapphire/pieces';
3
3
  import { CronJob } from 'cron';
4
4
  import { CronTask } from './CronTask.mjs';
5
+ import { Info, DateTime, FixedOffsetZone } from 'luxon';
5
6
 
6
7
  var _CronTaskStore = class _CronTaskStore extends Store {
7
8
  constructor() {
@@ -42,7 +43,7 @@ var _CronTaskStore = class _CronTaskStore extends Store {
42
43
  onTick: /* @__PURE__ */ __name(() => void value.run.bind(value)(), "onTick"),
43
44
  start: false,
44
45
  context: value,
45
- timeZone: options.timeZone ?? defaultTimezone
46
+ timeZone: this.formatLuxonZone(options.timeZone ?? defaultTimezone)
46
47
  });
47
48
  } catch (error) {
48
49
  value.error("Encountered an error while creating the cron job", error);
@@ -65,6 +66,19 @@ var _CronTaskStore = class _CronTaskStore extends Store {
65
66
  this.stopAll();
66
67
  return super.clear();
67
68
  }
69
+ /**
70
+ * Formats a Luxon-compatible timezone string into a TZ timezone string.
71
+ * This is required because Sentry requires time zones to be in TZ format.
72
+ * @param timezone The Luxon-compatible timezone to format.
73
+ * @returns The formatted TZ timezone.
74
+ * @private
75
+ */
76
+ formatLuxonZone(timezone) {
77
+ const zone = Info.normalizeZone(timezone);
78
+ if (!zone.isValid) return DateTime.local().zoneName;
79
+ if (zone instanceof FixedOffsetZone) return zone.ianaName;
80
+ return zone.name;
81
+ }
68
82
  };
69
83
  __name(_CronTaskStore, "CronTaskStore");
70
84
  var CronTaskStore = _CronTaskStore;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/CronTaskStore.ts"],"names":[],"mappings":";;;;;AAIO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsB,KAA8B,CAAA;AAAA,EACzD,WAAc,GAAA;AACpB,IAAA,KAAA,CAAM,QAAU,EAAA,EAAE,IAAM,EAAA,YAAA,EAAc,CAAA,CAAA;AAAA,GACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,QAAW,GAAA;AACjB,IAAW,KAAA,MAAA,IAAA,IAAQ,IAAK,CAAA,MAAA,EAAU,EAAA;AACjC,MAAI,IAAA,CAAC,KAAK,OAAS,EAAA,SAAA;AACnB,MAAA,IAAA,CAAK,IAAI,KAAM,EAAA,CAAA;AAAA,KAChB;AAEA,IAAA,KAAA,CAAM,MAAS,GAAA,CAAA,UAAA,EAAa,IAAK,CAAA,IAAI,CAAsC,oCAAA,CAAA,CAAA,CAAA;AAC3E,IAAO,OAAA,IAAA,CAAA;AAAA,GACR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,OAAU,GAAA;AAChB,IAAW,KAAA,MAAA,IAAA,IAAQ,IAAK,CAAA,MAAA,EAAU,EAAA;AACjC,MAAI,IAAA,CAAC,IAAK,CAAA,GAAA,CAAI,O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AAI,IAAK,EAAA,CAAA;AAAA,KACf;AAEA,IAAO,OAAA,KAAA,CAAM,OAAO,GAAG,CAAA,CAAA;AAAA,GACxB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMgB,KAAQ,GAAA;AACvB,IAAA,IAAA,CAAK,OAAQ,EAAA,CAAA;AACb,IAAA,OAAO,MAAM,KAAM,EAAA,CAAA;AAAA,GACpB;AACD,CAAA,CAAA;AAzEiE,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA,CAAA;AAA1D,IAAM,aAAN,GAAA","file":"CronTaskStore.mjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { CronJob } from 'cron';\nimport { CronTask } from './CronTask';\n\nexport class CronTaskStore extends Store<CronTask, 'cron-tasks'> {\n\tpublic constructor() {\n\t\tsuper(CronTask, { name: 'cron-tasks' });\n\t}\n\n\t/**\n\t * Loops over all tasks and starts those that are enabled.\n\t * This gets called automatically when the Client is ready.\n\t * @returns CronTaskStore\n\t */\n\tpublic startAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled) continue;\n\t\t\ttask.job.start();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [START] Started all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Loops over all tasks and stops those that are running.\n\t * @returns CronTaskStore\n\t */\n\tpublic stopAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.job.running) continue;\n\t\t\ttask.job.stop();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [STOP] Stopped all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\tpublic override set(key: string, value: CronTask): this {\n\t\tconst { options } = value;\n\n\t\tconst { sentry, defaultTimezone } = this.container.cron;\n\t\tconst cronJob = sentry ? sentry.cron.instrumentCron(CronJob, key) : CronJob;\n\n\t\ttry {\n\t\t\tvalue.job = cronJob.from({\n\t\t\t\t...options,\n\t\t\t\tonTick: () => void value.run.bind(value)(),\n\t\t\t\tstart: false,\n\t\t\t\tcontext: value,\n\t\t\t\ttimeZone: options.timeZone ?? defaultTimezone\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tvalue.error('Encountered an error while creating the cron job', error);\n\t\t\tvoid value.unload();\n\t\t}\n\n\t\treturn super.set(key, value);\n\t}\n\n\tpublic override delete(key: string) {\n\t\tconst task = this.get(key);\n\t\tif (task?.job.running) {\n\t\t\ttask.job.stop();\n\t\t}\n\n\t\treturn super.delete(key);\n\t}\n\n\t/**\n\t * Stops all running cron jobs and clears the store.\n\t * @returns void\n\t */\n\tpublic override clear() {\n\t\tthis.stopAll();\n\t\treturn super.clear();\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/CronTaskStore.ts"],"names":[],"mappings":";;;;;;AAKO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsB,KAA8B,CAAA;AAAA,EACzD,WAAc,GAAA;AACpB,IAAA,KAAA,CAAM,QAAU,EAAA,EAAE,IAAM,EAAA,YAAA,EAAc,CAAA,CAAA;AAAA,GACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,QAAW,GAAA;AACjB,IAAW,KAAA,MAAA,IAAA,IAAQ,IAAK,CAAA,MAAA,EAAU,EAAA;AACjC,MAAI,IAAA,CAAC,KAAK,OAAS,EAAA,SAAA;AACnB,MAAA,IAAA,CAAK,IAAI,KAAM,EAAA,CAAA;AAAA,KAChB;AAEA,IAAA,KAAA,CAAM,MAAS,GAAA,CAAA,UAAA,EAAa,IAAK,CAAA,IAAI,CAAsC,oCAAA,CAAA,CAAA,CAAA;AAC3E,IAAO,OAAA,IAAA,CAAA;AAAA,GACR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,OAAU,GAAA;AAChB,IAAW,KAAA,MAAA,IAAA,IAAQ,IAAK,CAAA,MAAA,EAAU,EAAA;AACjC,MAAI,IAAA,CAAC,IAAK,CAAA,GAAA,CAAI,OAAS,EAAA,SAAA;AACvB,MAAA,IAAA,CAAK,IA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AA,CAAA;AAAA,KACf;AAEA,IAAO,OAAA,KAAA,CAAM,OAAO,GAAG,CAAA,CAAA;AAAA,GACxB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMgB,KAAQ,GAAA;AACvB,IAAA,IAAA,CAAK,OAAQ,EAAA,CAAA;AACb,IAAA,OAAO,MAAM,KAAM,EAAA,CAAA;AAAA,GACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASQ,gBAAgB,QAAmC,EAAA;AAC1D,IAAM,MAAA,IAAA,GAAO,IAAK,CAAA,aAAA,CAAc,QAAQ,CAAA,CAAA;AAGxC,IAAA,IAAI,CAAC,IAAK,CAAA,OAAA,EAAgB,OAAA,QAAA,CAAS,OAAQ,CAAA,QAAA,CAAA;AAG3C,IAAI,IAAA,IAAA,YAAgB,eAAiB,EAAA,OAAO,IAAK,CAAA,QAAA,CAAA;AAGjD,IAAA,OAAO,IAAK,CAAA,IAAA,CAAA;AAAA,GACb;AACD,CAAA,CAAA;AA7FiE,MAAA,CAAA,cAAA,EAAA,eAAA,CAAA,CAAA;AAA1D,IAAM,aAAN,GAAA","file":"CronTaskStore.mjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { CronJob } from 'cron';\nimport { CronTask } from './CronTask';\nimport { Info, DateTime, FixedOffsetZone, type Zone } from 'luxon';\n\nexport class CronTaskStore extends Store<CronTask, 'cron-tasks'> {\n\tpublic constructor() {\n\t\tsuper(CronTask, { name: 'cron-tasks' });\n\t}\n\n\t/**\n\t * Loops over all tasks and starts those that are enabled.\n\t * This gets called automatically when the Client is ready.\n\t * @returns CronTaskStore\n\t */\n\tpublic startAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.enabled) continue;\n\t\t\ttask.job.start();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [START] Started all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Loops over all tasks and stops those that are running.\n\t * @returns CronTaskStore\n\t */\n\tpublic stopAll() {\n\t\tfor (const task of this.values()) {\n\t\t\tif (!task.job.running) continue;\n\t\t\ttask.job.stop();\n\t\t}\n\n\t\tStore.logger?.(`[STORE => ${this.name}] [STOP] Stopped all cronjob tasks.`);\n\t\treturn this;\n\t}\n\n\tpublic override set(key: string, value: CronTask): this {\n\t\tconst { options } = value;\n\n\t\tconst { sentry, defaultTimezone } = this.container.cron;\n\t\tconst cronJob = sentry ? sentry.cron.instrumentCron(CronJob, key) : CronJob;\n\n\t\ttry {\n\t\t\tvalue.job = cronJob.from({\n\t\t\t\t...options,\n\t\t\t\tonTick: () => void value.run.bind(value)(),\n\t\t\t\tstart: false,\n\t\t\t\tcontext: value,\n\t\t\t\ttimeZone: this.formatLuxonZone(options.timeZone ?? defaultTimezone)\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tvalue.error('Encountered an error while creating the cron job', error);\n\t\t\tvoid value.unload();\n\t\t}\n\n\t\treturn super.set(key, value);\n\t}\n\n\tpublic override delete(key: string) {\n\t\tconst task = this.get(key);\n\t\tif (task?.job.running) {\n\t\t\ttask.job.stop();\n\t\t}\n\n\t\treturn super.delete(key);\n\t}\n\n\t/**\n\t * Stops all running cron jobs and clears the store.\n\t * @returns void\n\t */\n\tpublic override clear() {\n\t\tthis.stopAll();\n\t\treturn super.clear();\n\t}\n\n\t/**\n\t * Formats a Luxon-compatible timezone string into a TZ timezone string.\n\t * This is required because Sentry requires time zones to be in TZ format.\n\t * @param timezone The Luxon-compatible timezone to format.\n\t * @returns The formatted TZ timezone.\n\t * @private\n\t */\n\tprivate formatLuxonZone(timezone?: string | Zone | number) {\n\t\tconst zone = Info.normalizeZone(timezone);\n\n\t\t// If the zone is invalid, return the system zone\n\t\tif (!zone.isValid) return DateTime.local().zoneName;\n\n\t\t// If the zone is a fixed offset zone, return the IANA name\n\t\tif (zone instanceof FixedOffsetZone) return zone.ianaName;\n\n\t\t// Otherwise, return the zone name\n\t\treturn zone.name;\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kingsworld/plugin-cron",
3
3
  "description": "A simple @sapphire/framework plugin that aims to make use of the cron package and allow users to make cron jobs within their Sapphire discord bot.",
4
- "version": "2.0.4-next.dd192a4",
4
+ "version": "2.1.0-next.47cb7ef",
5
5
  "author": "Seren_Modz 21 <seren@kings-world.net>",
6
6
  "license": "MIT",
7
7
  "main": "dist/cjs/index.cjs",
@@ -52,6 +52,7 @@
52
52
  "@favware/cliff-jumper": "^4.1.0",
53
53
  "@favware/rollup-type-bundler": "^3.3.0",
54
54
  "@sentry/node": "^8.32.0",
55
+ "@types/luxon": "^3.4.2",
55
56
  "@types/node": "^20.16.10",
56
57
  "concurrently": "^9.0.1",
57
58
  "tsup": "^8.3.0",