@kingsworld/plugin-cron 2.1.1-next.fed76b6 → 2.1.2-next.0f52b97
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/CHANGELOG.md +10 -0
- package/README.md +4 -4
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +3 -2
- package/dist/cjs/lib/structures/CronTask.cjs.map +1 -1
- package/dist/cjs/lib/structures/CronTaskStore.cjs +2 -2
- package/dist/cjs/lib/structures/CronTaskStore.cjs.map +1 -1
- package/dist/cjs/register.cjs.map +1 -1
- package/dist/esm/index.d.mts +3 -2
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/structures/CronTask.mjs.map +1 -1
- package/dist/esm/lib/structures/CronTaskStore.mjs +2 -2
- package/dist/esm/lib/structures/CronTaskStore.mjs.map +1 -1
- package/dist/esm/register.mjs.map +1 -1
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
+
# [@kingsworld/plugin-cron@2.1.1](https://github.com/Kings-World/sapphire-plugins/compare/@kingsworld/plugin-cron@2.1.0...@kingsworld/plugin-cron@2.1.1) - (2025-04-05)
|
6
|
+
|
7
|
+
## 🐛 Bug Fixes
|
8
|
+
|
9
|
+
- **deps:** Update all non-major dependencies ([83f972e](https://github.com/Kings-World/sapphire-plugins/commit/83f972eda0f3db62cfab8916e5c444abc0247e10)) ([#97](https://github.com/Kings-World/sapphire-plugins/pull/97) by @renovate[bot])
|
10
|
+
- **deps:** Update dependency cron to v4 ([1550eff](https://github.com/Kings-World/sapphire-plugins/commit/1550eff0705e5430281291aeb0fe18a830186915)) ([#91](https://github.com/Kings-World/sapphire-plugins/pull/91) by @renovate[bot])
|
11
|
+
- **deps:** Update all non-major dependencies ([d5bd44f](https://github.com/Kings-World/sapphire-plugins/commit/d5bd44fbbe46d8aaa92b6157dccb9536debc66a0)) ([#80](https://github.com/Kings-World/sapphire-plugins/pull/80) by @renovate[bot])
|
12
|
+
- **deps:** Update all non-major dependencies ([fab1c9f](https://github.com/Kings-World/sapphire-plugins/commit/fab1c9f661175bc9c2fdfc7d9ab3af59d16acc6f)) ([#79](https://github.com/Kings-World/sapphire-plugins/pull/79) by @renovate[bot])
|
13
|
+
- **deps:** Update all non-major dependencies ([e44b9ef](https://github.com/Kings-World/sapphire-plugins/commit/e44b9efa5b164699dd4393188c38e6f3fdadcc3e)) ([#75](https://github.com/Kings-World/sapphire-plugins/pull/75) by @renovate[bot])
|
14
|
+
|
5
15
|
# [@kingsworld/plugin-cron@2.1.0](https://github.com/Kings-World/sapphire-plugins/compare/@kingsworld/plugin-cron@2.0.3...@kingsworld/plugin-cron@2.1.0) - (2024-10-03)
|
6
16
|
|
7
17
|
## 🚀 Features
|
package/README.md
CHANGED
@@ -16,14 +16,14 @@ This plugin adds support for cron tasks to the Sapphire framework. It uses the [
|
|
16
16
|
|
17
17
|
## Features
|
18
18
|
|
19
|
-
-
|
20
|
-
-
|
19
|
+
- Full TypeScript support
|
20
|
+
- Includes ESM entrypoint
|
21
21
|
|
22
22
|
## Installation
|
23
23
|
|
24
24
|
`@kingsworld/plugin-cron` depends on the following packages. Be sure to install these along with this package!
|
25
25
|
|
26
|
-
-
|
26
|
+
- [`@sapphire/framework`](https://www.npmjs.com/package/@sapphire/framework)
|
27
27
|
|
28
28
|
You can use the following command to install this package along with `cron`, or replace `npm install` with your package manager of choice.
|
29
29
|
|
@@ -61,7 +61,7 @@ const options = {
|
|
61
61
|
};
|
62
62
|
```
|
63
63
|
|
64
|
-
-
|
64
|
+
- The `disableSentry` option is used to disable Sentry's cron monitoring. By default, it is set to `false`, which means Sentry cron monitoring is enabled if the `@sentry/node` package is installed and configured. This makes using Sentry an opt-in feature - you first opt in by installing `@sentry/node`. The `disableSentry` option then allows you to opt out in specific situations. You can set this to `true` to disable cron monitoring, which can be useful during development or if you haven't provided a Sentry DSN. If you don't use Sentry at all (i.e., `@sentry/node` is not installed), this option has no effect and can be safely ignored.
|
65
65
|
|
66
66
|
In order to use the cron tasks anywhere other than a piece (commands, arguments, preconditions, etc.), you must first import the `container` property of `@sapphire/framework`. For pieces, you can simply use `this.container.cron` to access this plugin's methods.
|
67
67
|
|
package/dist/cjs/index.cjs
CHANGED
@@ -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.1.
|
9
|
+
var version = "2.1.2-next.0f52b97";
|
10
10
|
|
11
11
|
exports.version = version;
|
12
12
|
Object.keys(CronTaskHandler_cjs).forEach(function (k) {
|
package/dist/cjs/index.cjs.map
CHANGED
@@ -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.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.1.2-next.0f52b97';\n"]}
|
package/dist/cjs/index.d.cts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Piece, Store } from '@sapphire/pieces';
|
2
2
|
import { Awaitable } from '@sapphire/framework';
|
3
|
-
import {
|
3
|
+
import { CronJob, CronJobParams } from 'cron';
|
4
4
|
import Sentry from '@sentry/node';
|
5
5
|
|
6
6
|
interface CronTaskHandlerOptions {
|
@@ -195,4 +195,5 @@ declare module 'discord.js' {
|
|
195
195
|
*/
|
196
196
|
declare const version: string;
|
197
197
|
|
198
|
-
export {
|
198
|
+
export { CronTask, CronTaskHandler, CronTaskStore, version };
|
199
|
+
export type { CronJobOptions, CronTaskHandlerOptions };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../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AA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA;AAAA;AAE3E,CAAA;AA/DyH,MAAA,CAAA,SAAA,EAAA,UAAA,CAAA;AAAlH,IAAe,QAAf,GAAA","file":"CronTask.cjs","sourcesContent":["import type { Awaitable } from '@sapphire/framework';\nimport { Piece } from '@sapphire/pieces';\nimport type { CronJob } from 'cron';\nimport type { CronJobOptions } from '../types/CronTaskTypes';\n\n/**\n * @example\n *\n * ```typescript\n * // ping.ts\n * import { CronTask } from '@kingsworld/plugin-cron';\n *\n * export class PingPong extends CronTask {\n * \tpublic constructor(context: CronTask.LoaderContext, options: CronTask.Options) {\n * \t\tsuper(context, {\n * \t\t\t...options,\n * \t\t\tcronTime: '* * * * *'\n * \t\t});\n * \t}\n *\n * \tpublic run() {\n * \t\tthis.info('Ping Pong! 🏓'); // CronTask[ping] Ping Pong! 🏓\n * \t}\n * }\n * ```\n */\nexport abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {\n\
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/CronTask.ts"],"names":["Piece"],"mappings":";;;;;;AA0BO,IAAe,SAAA,GAAf,MAAe,SAAA,SAAsEA,YAA6B,CAAA;AAAA,EAGjH,WAAA,CAAY,SAAiC,OAAkB,EAAA;AACrE,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AAAA;AACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWO,IAAA,CAAK,YAAoB,KAAkB,EAAA;AACjD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,IAAA,CAAK,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA;AAAA;AACzE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA;AAAA;AAC1E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,IAAA,CAAK,YAAoB,KAAkB,EAAA;AACjD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,IAAA,CAAK,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA;AAAA;AACzE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA;AAAA;AAC1E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA;AAAA;AAE3E,CAAA;AA/DyH,MAAA,CAAA,SAAA,EAAA,UAAA,CAAA;AAAlH,IAAe,QAAf,GAAA","file":"CronTask.cjs","sourcesContent":["import type { Awaitable } from '@sapphire/framework';\nimport { Piece } from '@sapphire/pieces';\nimport type { CronJob } from 'cron';\nimport type { CronJobOptions } from '../types/CronTaskTypes';\n\n/**\n * @example\n *\n * ```typescript\n * // ping.ts\n * import { CronTask } from '@kingsworld/plugin-cron';\n *\n * export class PingPong extends CronTask {\n * \tpublic constructor(context: CronTask.LoaderContext, options: CronTask.Options) {\n * \t\tsuper(context, {\n * \t\t\t...options,\n * \t\t\tcronTime: '* * * * *'\n * \t\t});\n * \t}\n *\n * \tpublic run() {\n * \t\tthis.info('Ping Pong! 🏓'); // CronTask[ping] Ping Pong! 🏓\n * \t}\n * }\n * ```\n */\nexport abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {\n\tdeclare public job: CronJob<null, CronTask>;\n\n\tpublic constructor(context: CronTask.LoaderContext, options: Options) {\n\t\tsuper(context, options);\n\t}\n\n\tpublic abstract run(): Awaitable<unknown>;\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.info('Hello world!'); // CronTask[my-task] Hello world!\n\t */\n\tpublic info(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.info(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!\n\t */\n\tpublic error(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.error(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.warn('Something is not right!'); // CronTask[my-task] Something is not right!\n\t */\n\tpublic warn(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.warn(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.debug('Something is happening!'); // CronTask[my-task] Something is happening!\n\t */\n\tpublic debug(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.debug(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.\n\t */\n\tpublic trace(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.trace(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n}\n\nexport namespace CronTask {\n\texport type Options = Piece.Options & CronJobOptions;\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'cron-tasks'>;\n}\n"]}
|
@@ -30,7 +30,7 @@ var _CronTaskStore = class _CronTaskStore extends pieces.Store {
|
|
30
30
|
*/
|
31
31
|
stopAll() {
|
32
32
|
for (const task of this.values()) {
|
33
|
-
if (!task.job.
|
33
|
+
if (!task.job.isActive) continue;
|
34
34
|
task.job.stop();
|
35
35
|
}
|
36
36
|
pieces.Store.logger?.(`[STORE => ${this.name}] [STOP] Stopped all cronjob tasks.`);
|
@@ -56,7 +56,7 @@ var _CronTaskStore = class _CronTaskStore extends pieces.Store {
|
|
56
56
|
}
|
57
57
|
delete(key) {
|
58
58
|
const task = this.get(key);
|
59
|
-
if (task?.job.
|
59
|
+
if (task?.job.isActive) {
|
60
60
|
task.job.stop();
|
61
61
|
}
|
62
62
|
return super.delete(key);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/CronTaskStore.ts"],"names":["Store","CronTask","CronJob","Info","DateTime","FixedOffsetZone"],"mappings":";;;;;;;;;AAKO,IAAM,cAAA,GAAN,MAAM,cAAA,SAAsBA,YAA8B,CAAA;AAAA,EACzD,WAAc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CAAA;AACzB,IAAI,IAAA,IAAA,EAAM,IAAI,QAAU,EAAA;AACvB,MAAA,IAAA,CAAK,IAAI,IAAK,EAAA;AAAA;AAGf,IAAO,OAAA,KAAA,CAAM,OAAO,GAAG,CAAA;AAAA;AACxB;AAAA;AAAA;AAAA;AAAA,EAMgB,KAAQ,GAAA;AACvB,IAAA,IAAA,CAAK,OAAQ,EAAA;AACb,IAAA,OAAO,MAAM,KAAM,EAAA;AAAA;AACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASQ,gBAAgB,QAAmC,EAAA;AAC1D,IAAM,MAAA,IAAA,GAAOC,UAAK,CAAA,aAAA,CAAc,QAAQ,CAAA;AAGxC,IAAA,IAAI,CAAC,IAAK,CAAA,OAAA,EAAgB,OAAAC,cAAA,CAAS,OAAQ,CAAA,QAAA;AAG3C,IAAI,IAAA,IAAA,YAAgBC,qBAAiB,EAAA,OAAO,IAAK,CAAA,QAAA;AAGjD,IAAA,OAAO,IAAK,CAAA,IAAA;AAAA;AAEd,CAAA;AA7FiE,MAAA,CAAA,cAAA,EAAA,eAAA,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.isActive) 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.isActive) {\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"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/register.ts"],"names":["Plugin","preGenericsInitialization","container","CronTaskHandler","postInitialization","CronTaskStore","preLogin","postLogin","SapphireClient"],"mappings":";;;;;;;AAMO,IAAM,eAAA,GAAN,MAAM,eAAA,SAAuBA,gBAAO,CAAA;AAAA,EAC1C,
|
1
|
+
{"version":3,"sources":["../../src/register.ts"],"names":["Plugin","preGenericsInitialization","container","CronTaskHandler","postInitialization","CronTaskStore","preLogin","postLogin","SapphireClient"],"mappings":";;;;;;;AAMO,IAAM,eAAA,GAAN,MAAM,eAAA,SAAuBA,gBAAO,CAAA;AAAA,EAC1C,QAAwBC,mCAAyB,CAAA,CAAwB,OAAwB,EAAA;AAChG,IAAAC,mBAAA,CAAU,IAAO,GAAA,IAAIC,yBAAgB,CAAA,OAAA,CAAQ,IAAI,CAAA;AAAA;AAClD,EAEA,QAAwBC,4BAAkB,CAAwB,GAAA;AACjE,IAAA,IAAA,CAAK,MAAO,CAAA,QAAA,CAAS,IAAIC,uBAAA,EAAe,CAAA;AAAA;AACzC,EAEA,cAA8BC,kBAAQ,CAAwB,GAAA;AAC7D,IAAI,IAAAJ,mBAAA,CAAU,KAAK,aAAe,EAAA;AAClC,IAAUA,mBAAA,CAAA,IAAA,CAAK,SAAS,MAAM,OAAO,cAAc,CAAE,CAAA,KAAA,CAAM,MAAM,MAAS,CAAA;AAAA;AAC3E,EAEA,QAAwBK,mBAAS,CAAwB,GAAA;AACxD,IAAAL,mBAAA,CAAU,KAAK,QAAS,EAAA;AAAA;AAE1B,CAAA;AAjB2C,MAAA,CAAA,eAAA,EAAA,gBAAA,CAAA;AAApC,IAAM,cAAN,GAAA;AAmBPM,wBAAA,CAAe,OAAQ,CAAA,qCAAA,CAAsC,cAAe,CAAAP,mCAAyB,GAAG,qCAAqC,CAAA;AAE7IO,wBAAA,CAAe,OAAQ,CAAA,8BAAA,CAA+B,cAAe,CAAAJ,4BAAkB,GAAG,8BAA8B,CAAA;AAExHI,wBAAA,CAAe,OAAQ,CAAA,oBAAA,CAAqB,cAAe,CAAAF,kBAAQ,GAAG,oBAAoB,CAAA;AAE1FE,wBAAA,CAAe,OAAQ,CAAA,qBAAA,CAAsB,cAAe,CAAAD,mBAAS,GAAG,qBAAqB,CAAA","file":"register.cjs","sourcesContent":["import './index';\n\nimport { container, Plugin, postInitialization, postLogin, preGenericsInitialization, preLogin, SapphireClient } from '@sapphire/framework';\nimport type { ClientOptions } from 'discord.js';\nimport { CronTaskHandler, CronTaskStore } from './index';\n\nexport class CronTaskPlugin extends Plugin {\n\tpublic static override [preGenericsInitialization](this: SapphireClient, options: ClientOptions) {\n\t\tcontainer.cron = new CronTaskHandler(options.cron);\n\t}\n\n\tpublic static override [postInitialization](this: SapphireClient) {\n\t\tthis.stores.register(new CronTaskStore());\n\t}\n\n\tpublic static override async [preLogin](this: SapphireClient) {\n\t\tif (container.cron.disableSentry) return;\n\t\tcontainer.cron.sentry = await import('@sentry/node').catch(() => undefined);\n\t}\n\n\tpublic static override [postLogin](this: SapphireClient) {\n\t\tcontainer.cron.startAll();\n\t}\n}\n\nSapphireClient.plugins.registerPreGenericsInitializationHook(CronTaskPlugin[preGenericsInitialization], 'Cron-Task-PreGenericsInitialization');\n\nSapphireClient.plugins.registerPostInitializationHook(CronTaskPlugin[postInitialization], 'Cron-Task-PostInitialization');\n\nSapphireClient.plugins.registerPreLoginHook(CronTaskPlugin[preLogin], 'Cron-Task-PreLogin');\n\nSapphireClient.plugins.registerPostLoginHook(CronTaskPlugin[postLogin], 'Cron-Task-PostLogin');\n"]}
|
package/dist/esm/index.d.mts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Piece, Store } from '@sapphire/pieces';
|
2
2
|
import { Awaitable } from '@sapphire/framework';
|
3
|
-
import {
|
3
|
+
import { CronJob, CronJobParams } from 'cron';
|
4
4
|
import Sentry from '@sentry/node';
|
5
5
|
|
6
6
|
interface CronTaskHandlerOptions {
|
@@ -195,4 +195,5 @@ declare module 'discord.js' {
|
|
195
195
|
*/
|
196
196
|
declare const version: string;
|
197
197
|
|
198
|
-
export {
|
198
|
+
export { CronTask, CronTaskHandler, CronTaskStore, version };
|
199
|
+
export type { CronJobOptions, CronTaskHandlerOptions };
|
package/dist/esm/index.mjs
CHANGED
@@ -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.1.
|
7
|
+
var version = "2.1.2-next.0f52b97";
|
8
8
|
|
9
9
|
export { version };
|
10
10
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
@@ -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.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.1.2-next.0f52b97';\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/CronTask.ts"],"names":[],"mappings":";;;AA0BO,IAAe,SAAA,GAAf,MAAe,SAAA,SAAsE,KAA6B,CAAA;AAAA,EAGjH,WAAA,CAAY,SAAiC,OAAkB,EAAA;AACrE,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AAAA;AACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWO,IAAA,CAAK,YAAoB,KAAkB,EAAA;AACjD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,IAAA,CAAK,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA;AAAA;AACzE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA;AAAA;AAC1E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,IAAA,CAAK,YAAoB,KAAkB,EAAA;AACjD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,IAAA,CAAK,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA;AAAA;AACzE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA;AAAA;AAC1E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA;AAAA;AAE3E,CAAA;AA/DyH,MAAA,CAAA,SAAA,EAAA,UAAA,CAAA;AAAlH,IAAe,QAAf,GAAA","file":"CronTask.mjs","sourcesContent":["import type { Awaitable } from '@sapphire/framework';\nimport { Piece } from '@sapphire/pieces';\nimport type { CronJob } from 'cron';\nimport type { CronJobOptions } from '../types/CronTaskTypes';\n\n/**\n * @example\n *\n * ```typescript\n * // ping.ts\n * import { CronTask } from '@kingsworld/plugin-cron';\n *\n * export class PingPong extends CronTask {\n * \tpublic constructor(context: CronTask.LoaderContext, options: CronTask.Options) {\n * \t\tsuper(context, {\n * \t\t\t...options,\n * \t\t\tcronTime: '* * * * *'\n * \t\t});\n * \t}\n *\n * \tpublic run() {\n * \t\tthis.info('Ping Pong! 🏓'); // CronTask[ping] Ping Pong! 🏓\n * \t}\n * }\n * ```\n */\nexport abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {\n\
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/CronTask.ts"],"names":[],"mappings":";;;AA0BO,IAAe,SAAA,GAAf,MAAe,SAAA,SAAsE,KAA6B,CAAA;AAAA,EAGjH,WAAA,CAAY,SAAiC,OAAkB,EAAA;AACrE,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AAAA;AACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWO,IAAA,CAAK,YAAoB,KAAkB,EAAA;AACjD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,IAAA,CAAK,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA;AAAA;AACzE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA;AAAA;AAC1E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,IAAA,CAAK,YAAoB,KAAkB,EAAA;AACjD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,IAAA,CAAK,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA;AAAA;AACzE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA;AAAA;AAC1E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,KAAA,CAAM,YAAoB,KAAkB,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAK,EAAA,EAAA,OAAO,CAAI,CAAA,EAAA,GAAG,KAAK,CAAA;AAAA;AAE3E,CAAA;AA/DyH,MAAA,CAAA,SAAA,EAAA,UAAA,CAAA;AAAlH,IAAe,QAAf,GAAA","file":"CronTask.mjs","sourcesContent":["import type { Awaitable } from '@sapphire/framework';\nimport { Piece } from '@sapphire/pieces';\nimport type { CronJob } from 'cron';\nimport type { CronJobOptions } from '../types/CronTaskTypes';\n\n/**\n * @example\n *\n * ```typescript\n * // ping.ts\n * import { CronTask } from '@kingsworld/plugin-cron';\n *\n * export class PingPong extends CronTask {\n * \tpublic constructor(context: CronTask.LoaderContext, options: CronTask.Options) {\n * \t\tsuper(context, {\n * \t\t\t...options,\n * \t\t\tcronTime: '* * * * *'\n * \t\t});\n * \t}\n *\n * \tpublic run() {\n * \t\tthis.info('Ping Pong! 🏓'); // CronTask[ping] Ping Pong! 🏓\n * \t}\n * }\n * ```\n */\nexport abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {\n\tdeclare public job: CronJob<null, CronTask>;\n\n\tpublic constructor(context: CronTask.LoaderContext, options: Options) {\n\t\tsuper(context, options);\n\t}\n\n\tpublic abstract run(): Awaitable<unknown>;\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.info('Hello world!'); // CronTask[my-task] Hello world!\n\t */\n\tpublic info(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.info(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!\n\t */\n\tpublic error(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.error(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.warn('Something is not right!'); // CronTask[my-task] Something is not right!\n\t */\n\tpublic warn(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.warn(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.debug('Something is happening!'); // CronTask[my-task] Something is happening!\n\t */\n\tpublic debug(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.debug(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n\n\t/**\n\t * A helper function to log messages with the `CronTask[${name}]` prefix.\n\t * @param message The message to include after the prefix\n\t * @param other Extra parameters to pass to the logger\n\t * @example\n\t * this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.\n\t */\n\tpublic trace(message: string, ...other: unknown[]) {\n\t\tthis.container.logger.trace(`CronTask[${this.name}] ${message}`, ...other);\n\t}\n}\n\nexport namespace CronTask {\n\texport type Options = Piece.Options & CronJobOptions;\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'cron-tasks'>;\n}\n"]}
|
@@ -27,7 +27,7 @@ var _CronTaskStore = class _CronTaskStore extends Store {
|
|
27
27
|
*/
|
28
28
|
stopAll() {
|
29
29
|
for (const task of this.values()) {
|
30
|
-
if (!task.job.
|
30
|
+
if (!task.job.isActive) continue;
|
31
31
|
task.job.stop();
|
32
32
|
}
|
33
33
|
Store.logger?.(`[STORE => ${this.name}] [STOP] Stopped all cronjob tasks.`);
|
@@ -53,7 +53,7 @@ var _CronTaskStore = class _CronTaskStore extends Store {
|
|
53
53
|
}
|
54
54
|
delete(key) {
|
55
55
|
const task = this.get(key);
|
56
|
-
if (task?.job.
|
56
|
+
if (task?.job.isActive) {
|
57
57
|
task.job.stop();
|
58
58
|
}
|
59
59
|
return super.delete(key);
|
@@ -1 +1 @@
|
|
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;AAAA;AACvC;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;AACnB,MAAA,IAAA,CAAK,IAAI,KAAM,EAAA;AAAA;AAGhB,IAAA,KAAA,CAAM,MAAS,GAAA,CAAA,UAAA,EAAa,IAAK,CAAA,IAAI,CAAsC,oCAAA,CAAA,CAAA;AAC3E,IAAO,OAAA,IAAA;AAAA;AACR;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,
|
1
|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MAAA,CAAA,cAAA,EAAA,eAAA,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.isActive) 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.isActive) {\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"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/register.ts"],"names":[],"mappings":";;;;AAMO,IAAM,eAAA,GAAN,MAAM,eAAA,SAAuB,MAAO,CAAA;AAAA,EAC1C,
|
1
|
+
{"version":3,"sources":["../../src/register.ts"],"names":[],"mappings":";;;;AAMO,IAAM,eAAA,GAAN,MAAM,eAAA,SAAuB,MAAO,CAAA;AAAA,EAC1C,QAAwB,yBAAyB,CAAA,CAAwB,OAAwB,EAAA;AAChG,IAAA,SAAA,CAAU,IAAO,GAAA,IAAI,eAAgB,CAAA,OAAA,CAAQ,IAAI,CAAA;AAAA;AAClD,EAEA,QAAwB,kBAAkB,CAAwB,GAAA;AACjE,IAAA,IAAA,CAAK,MAAO,CAAA,QAAA,CAAS,IAAI,aAAA,EAAe,CAAA;AAAA;AACzC,EAEA,cAA8B,QAAQ,CAAwB,GAAA;AAC7D,IAAI,IAAA,SAAA,CAAU,KAAK,aAAe,EAAA;AAClC,IAAU,SAAA,CAAA,IAAA,CAAK,SAAS,MAAM,OAAO,cAAc,CAAE,CAAA,KAAA,CAAM,MAAM,MAAS,CAAA;AAAA;AAC3E,EAEA,QAAwB,SAAS,CAAwB,GAAA;AACxD,IAAA,SAAA,CAAU,KAAK,QAAS,EAAA;AAAA;AAE1B,CAAA;AAjB2C,MAAA,CAAA,eAAA,EAAA,gBAAA,CAAA;AAApC,IAAM,cAAN,GAAA;AAmBP,cAAA,CAAe,OAAQ,CAAA,qCAAA,CAAsC,cAAe,CAAA,yBAAyB,GAAG,qCAAqC,CAAA;AAE7I,cAAA,CAAe,OAAQ,CAAA,8BAAA,CAA+B,cAAe,CAAA,kBAAkB,GAAG,8BAA8B,CAAA;AAExH,cAAA,CAAe,OAAQ,CAAA,oBAAA,CAAqB,cAAe,CAAA,QAAQ,GAAG,oBAAoB,CAAA;AAE1F,cAAA,CAAe,OAAQ,CAAA,qBAAA,CAAsB,cAAe,CAAA,SAAS,GAAG,qBAAqB,CAAA","file":"register.mjs","sourcesContent":["import './index';\n\nimport { container, Plugin, postInitialization, postLogin, preGenericsInitialization, preLogin, SapphireClient } from '@sapphire/framework';\nimport type { ClientOptions } from 'discord.js';\nimport { CronTaskHandler, CronTaskStore } from './index';\n\nexport class CronTaskPlugin extends Plugin {\n\tpublic static override [preGenericsInitialization](this: SapphireClient, options: ClientOptions) {\n\t\tcontainer.cron = new CronTaskHandler(options.cron);\n\t}\n\n\tpublic static override [postInitialization](this: SapphireClient) {\n\t\tthis.stores.register(new CronTaskStore());\n\t}\n\n\tpublic static override async [preLogin](this: SapphireClient) {\n\t\tif (container.cron.disableSentry) return;\n\t\tcontainer.cron.sentry = await import('@sentry/node').catch(() => undefined);\n\t}\n\n\tpublic static override [postLogin](this: SapphireClient) {\n\t\tcontainer.cron.startAll();\n\t}\n}\n\nSapphireClient.plugins.registerPreGenericsInitializationHook(CronTaskPlugin[preGenericsInitialization], 'Cron-Task-PreGenericsInitialization');\n\nSapphireClient.plugins.registerPostInitializationHook(CronTaskPlugin[postInitialization], 'Cron-Task-PostInitialization');\n\nSapphireClient.plugins.registerPreLoginHook(CronTaskPlugin[preLogin], 'Cron-Task-PreLogin');\n\nSapphireClient.plugins.registerPostLoginHook(CronTaskPlugin[postLogin], 'Cron-Task-PostLogin');\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.1.
|
4
|
+
"version": "2.1.2-next.0f52b97",
|
5
5
|
"author": "Seren_Modz 21 <seren@kings-world.net>",
|
6
6
|
"license": "MIT",
|
7
7
|
"main": "dist/cjs/index.cjs",
|
@@ -36,7 +36,7 @@
|
|
36
36
|
"scripts": {
|
37
37
|
"build": "tsup && yarn build:types && yarn build:rename-cjs-register",
|
38
38
|
"build:types": "concurrently \"yarn:build:types:*\"",
|
39
|
-
"build:types:cjs": "rollup-type-bundler -d dist/cjs -
|
39
|
+
"build:types:cjs": "rollup-type-bundler -d dist/cjs --output-typings-file-extension .cts",
|
40
40
|
"build:types:esm": "rollup-type-bundler -d dist/esm -t .mts",
|
41
41
|
"build:types:cleanup": "tsx ../../scripts/clean-register-imports.mts",
|
42
42
|
"build:rename-cjs-register": "tsx ../../scripts/rename-cjs-register.mts",
|
@@ -46,17 +46,17 @@
|
|
46
46
|
"check-update": "cliff-jumper --dry-run"
|
47
47
|
},
|
48
48
|
"dependencies": {
|
49
|
-
"cron": "^
|
49
|
+
"cron": "^4.1.3"
|
50
50
|
},
|
51
51
|
"devDependencies": {
|
52
|
-
"@favware/cliff-jumper": "^
|
53
|
-
"@favware/rollup-type-bundler": "^
|
54
|
-
"@sentry/node": "^
|
55
|
-
"@types/luxon": "^3.
|
56
|
-
"@types/node": "^22.
|
57
|
-
"concurrently": "^9.1.
|
58
|
-
"tsup": "^8.
|
59
|
-
"tsx": "^4.19.
|
52
|
+
"@favware/cliff-jumper": "^6.0.0",
|
53
|
+
"@favware/rollup-type-bundler": "^4.0.0",
|
54
|
+
"@sentry/node": "^9.11.0",
|
55
|
+
"@types/luxon": "^3.6.2",
|
56
|
+
"@types/node": "^22.14.0",
|
57
|
+
"concurrently": "^9.1.2",
|
58
|
+
"tsup": "^8.4.0",
|
59
|
+
"tsx": "^4.19.3",
|
60
60
|
"typescript": "~5.4.5"
|
61
61
|
},
|
62
62
|
"homepage": "https://github.com/Kings-World/sapphire-plugins",
|