@kingsworld/plugin-cron 1.5.2 → 2.0.0-next.023f779

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 ADDED
File without changes
package/README.md CHANGED
@@ -1,122 +1,152 @@
1
+ <div align="center">
2
+
1
3
  # @kingsworld/plugin-cron
2
4
 
3
- A simple [@sapphire/framework](https://www.npmjs.com/package/@sapphire/framework) plugin that aims to make use of the [cron](https://www.npmjs.com/package/cron) package and allow users to make cron jobs within their Sapphire discord bot.
5
+ **Plugin for <a href="https://github.com/sapphiredev/framework">@sapphire/framework</a> to add support for cron tasks using <a href="https://github.com/kelektiv/node-cron">cron</a>.**
6
+
7
+ [![GitHub](https://img.shields.io/github/license/Kings-World/sapphire-plugins)](https://github.com/Kings-World/sapphire-plugins/blob/main/LICENSE.md)
8
+ [![npm bundle size](https://pkg-size.dev/badge/bundle/83411)](https://pkg-size.dev/@kingsworld/plugin-cron)
9
+ [![npm](https://img.shields.io/npm/v/@kingsworld/plugin-cron?color=crimson&logo=npm&style=flat-square)](https://www.npmjs.com/package/@kingsworld/plugin-cron)
10
+
11
+ </div>
12
+
13
+ ## Description
14
+
15
+ This plugin adds support for cron tasks to the Sapphire framework. It uses the [cron](ttps://www.npmjs.com/package/@kingsworld/plugin-cron) package to create and manage cron tasks.
16
+
17
+ ## Features
18
+
19
+ - Full TypeScript support
20
+ - Includes ESM entrypoint
4
21
 
5
22
  ## Installation
6
23
 
24
+ `@kingsworld/plugin-cron` depends on the following packages. Be sure to install these along with this package!
25
+
26
+ - [`@sapphire/framework`](https://www.npmjs.com/package/@sapphire/framework)
27
+
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
+
7
30
  ```sh
8
- yarn add @kingsworld/plugin-cron @sapphire/framework
31
+ npm install @kingsworld/plugin-cron @sapphire/framework
9
32
  ```
10
33
 
11
34
  ## Usage
12
35
 
13
- Make sure to register the plugin before creating the client
36
+ This registers the necessary options and methods in the Sapphire client to be able to use the cron plugin.
14
37
 
15
38
  ```ts
16
- import "@kingsworld/plugin-cron/register";
39
+ // Main bot file
40
+ // Be sure to register the plugin before instantiating the client.
41
+ import '@kingsworld/plugin-cron/register';
17
42
  ```
18
43
 
19
- If you would like to set the default cron job timezone for all your cron jobs, you can do so within the client options. A list of TZ identifers can be found on [Wikipedia](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
44
+ Then, you can configure the plugin in the configuration options in your SapphireClient extension class or initializer. This will either be located in your new SapphireClient constructor call, or super in your constructor method if you use an extension class.
20
45
 
21
46
  ```ts
22
- new SapphireClient({
23
- ...otherClientOptions,
24
- cron: {
25
- // the cron object is optional
26
- defaultTimezone: "Europe/London", // the cron package defaults to UTC
27
- },
28
- });
47
+ const options = {
48
+ ...otherClientOptionsGoHere,
49
+ cron: {
50
+ /**
51
+ * Whether to disable Sentry cron monitoring
52
+ * @default false
53
+ */
54
+ disableSentry: false,
55
+ /**
56
+ * The timezone to use for the cron tasks
57
+ * @default 'system'
58
+ */
59
+ defaultTimezone: 'Europe/London'
60
+ }
61
+ };
29
62
  ```
30
63
 
31
- However, if you would like to do so for a single task, you can do so in the cron task options
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.
32
65
 
33
- ```js
34
- {
35
- cronTime: "* * * * *", // every minute
36
- timeZone: "Europe/London"
37
- }
38
- ```
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.
39
67
 
40
- ### Creating a task
68
+ This is a simple example of how to start a task from a service.
41
69
 
42
- Cron Tasks come with their own store, just like Sapphire commands, listeners, and so on. They must be located within a `cron-tasks` directory that is located alongside your other stores.
70
+ ```typescript
71
+ import { container } from '@sapphire/framework';
43
72
 
44
- ```
45
- src
46
- ├── listeners
47
- | └── ready.ts
48
- └── cron-tasks
49
- └── ping.ts
73
+ export class MyAwesomeService {
74
+ public createAwesomeTask() {
75
+ const task = container.cron.store.get('my-awesome-task');
76
+
77
+ task.job.start();
78
+ }
79
+ }
50
80
  ```
51
81
 
52
- Using decorators from [@sapphire/decorators](https://www.npmjs.com/package/@sapphire/decorators):
82
+ This is a simple example of how to start all tasks from a service.
53
83
 
54
- ```ts
55
- import { ApplyOptions } from "@sapphire/decorators";
56
- import { CronTask } from "@kingsworld/plugin-cron";
84
+ ```typescript
85
+ import { container } from '@sapphire/framework';
57
86
 
58
- @ApplyOptions<CronTask.Options>({
59
- cronTime: "* * * * *",
60
- })
61
- export class PingPong extends CronTask {
62
- run() {
63
- this.container.logger.info("Ping Pong! 🏓");
64
- }
87
+ export class MyAwesomeService {
88
+ public createAwesomeTask() {
89
+ container.cron.startAll();
90
+ }
65
91
  }
66
92
  ```
67
93
 
68
- Using the class constructor:
94
+ It's important to note that the `startAll()` method is called automatically when the client is ready. Therefore, it's generally not necessary to call this method manually, unless you have a specific need to restart all cron tasks at some point after the client has been initialized.
69
95
 
70
- ```ts
71
- import { CronTask } from "@kingsworld/plugin-cron";
96
+ ### Create a task handler
97
+
98
+ Cron tasks use their own store, like other types of pieces. You can create a directory alongside your commands directory named `cron-tasks` and place your tasks there, but they must inherit from `CronTask`, like so.
99
+
100
+ ##### Creating the Piece:
101
+
102
+ ```typescript
103
+ import { CronTask } from '@kingsworld/plugin-cron';
72
104
 
73
105
  export class PingPong extends CronTask {
74
- constructor(context: CronTask.LoaderContext, options: CronTask.Options) {
75
- super(context, {
76
- ...options,
77
- cronTime: "* * * * *",
78
- });
79
- }
80
-
81
- run() {
82
- this.container.logger.info("Ping Pong! 🏓");
83
- }
106
+ public constructor(context: CronTask.LoaderContext, options: CronTask.Options) {
107
+ super(context, {
108
+ ...options,
109
+ cronTime: '* * * * *'
110
+ });
111
+ }
112
+
113
+ public run() {
114
+ this.container.logger.info('Ping Pong! 🏓');
115
+ }
84
116
  }
85
117
  ```
86
118
 
87
- ### Frequently Asked Questions
119
+ ### Logging Helpers
88
120
 
89
- ##### What does the `this.info()`, `this.error()`, `this.warn()`, `this.debug()`, and `this.trace()` methods do in the CronTask class?
121
+ The `CronTask` class provides logging helpers that are similar to the ones provided by the `Logger` class. These helpers are `info`, `error`, `warn`, `debug`, and `trace`. They all take a single string argument, which is the message to log.
90
122
 
91
- These methods are small helpers towards Sapphire's logger that prefixes logs with `CronTask[$name]`. The helpers are optional, however, I find them useful when using them in my own projects.
123
+ This is an example of how to use the `info` helper:
124
+
125
+ ```typescript
126
+ import { CronTask } from '@kingsworld/plugin-cron';
92
127
 
93
- ```ts
94
128
  export class PingPong extends CronTask {
95
- run() {
96
- this.info("Ping Pong! 🏓"); // INFO - CronTask[ping] Ping Pong! 🏓
97
- this.error("Ping Pong! 🏓"); // ERROR - CronTask[ping] Ping Pong! 🏓
98
- this.warn("Ping Pong! 🏓"); // WARN - CronTask[ping] Ping Pong! 🏓
99
- this.debug("Ping Pong! 🏓"); // DEBUG - CronTask[ping] Ping Pong! 🏓
100
- this.trace("Ping Pong! 🏓"); // TRACE - CronTask[ping] Ping Pong! 🏓
101
- }
129
+ public constructor(context: CronTask.LoaderContext, options: CronTask.Options) {
130
+ super(context, {
131
+ ...options,
132
+ cronTime: '* * * * *'
133
+ });
134
+ }
135
+
136
+ public run() {
137
+ this.info('Ping Pong! 🏓'); // CronTask[ping] Ping Pong! 🏓
138
+ }
102
139
  }
103
140
  ```
104
141
 
105
- ### Contributing
142
+ ## Contributors
106
143
 
107
- #### Getting started
144
+ Please make sure to read the [Contributing Guide][contributing] before making a pull request.
108
145
 
109
- First, clone the repo using git SSH, the GitHub CLI, or HTTP
146
+ Thank you to all the people who already contributed to Sapphire!
110
147
 
111
- ```sh
112
- git clone git@github.com:Kings-World/sapphire-plugins.git # ssh
113
- git clone https://github.com/Kings-World/sapphire-plugins.git # http
114
- gh repo clone Kings-World/sapphire-plugins # github cli
115
- ```
148
+ <a href="https://github.com/Kings-World/sapphire-plugins/graphs/contributors">
149
+ <img src="https://contrib.rocks/image?repo=Kings-World/sapphire-plugins" />
150
+ </a>
116
151
 
117
- Finally, install the dependencies using Yarn
118
-
119
- ```sh
120
- yarn # shorthand
121
- yarn install # full command
122
- ```
152
+ [contributing]: https://github.com/Kings-World/sapphire-plugins/blob/main/.github/CONTRIBUTING.md
@@ -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 = "1.5.1";
9
+ var version = "2.0.0-next.023f779";
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 interface Container {\n cron: CronTaskHandler;\n }\n\n interface StoreRegistryEntries {\n \"cron-tasks\": CronTaskStore;\n }\n}\n\ndeclare module \"discord.js\" {\n export interface ClientOptions {\n cron?: CronTaskHandlerOptions;\n }\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 = \"1.5.1\";\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?: 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.0-next.023f779';\n"]}
@@ -1,71 +1,167 @@
1
1
  import { Piece, Store } from '@sapphire/pieces';
2
- import { CronJobParams, CronJob } from 'cron';
3
2
  import { Awaitable } from '@sapphire/framework';
3
+ import { CronJobParams, CronJob } from 'cron';
4
4
  import Sentry from '@sentry/node';
5
5
 
6
6
  interface CronTaskHandlerOptions {
7
7
  /**
8
8
  * The default timezone to use for all cron tasks.
9
9
  * You can override this per task, using the timeZone option.
10
- * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
11
- * @default "UTC"
10
+ * @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone
11
+ * @default 'system'
12
12
  */
13
- defaultTimezone?: string;
13
+ defaultTimezone: string;
14
14
  /**
15
15
  * The ability to opt-out of instrumenting cron jobs with Sentry.
16
16
  * If you don't use Sentry, you can ignore this option.
17
17
  * @see https://docs.sentry.io/product/crons/
18
- * @default undefined // technically false
18
+ * @default false
19
19
  */
20
- disableSentry?: boolean;
20
+ disableSentry: boolean;
21
21
  }
22
- type CronJobOptions = Omit<CronJobParams<null, CronTask>, "onTick" | "onComplete" | "start" | "context" | "utcOffset">;
22
+ type CronJobOptions = Omit<CronJobParams<null, CronTask>, 'onTick' | 'onComplete' | 'start' | 'context' | 'utcOffset'>;
23
23
 
24
- declare abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, "cron-tasks"> {
24
+ /**
25
+ * @example
26
+ *
27
+ * ```typescript
28
+ * // ping.ts
29
+ * import { CronTask } from '@kingsworld/plugin-cron';
30
+ *
31
+ * export class PingPong extends CronTask {
32
+ * public constructor(context: CronTask.LoaderContext, options: CronTask.Options) {
33
+ * super(context, {
34
+ * ...options,
35
+ * cronTime: '* * * * *'
36
+ * });
37
+ * }
38
+ *
39
+ * public run() {
40
+ * this.info('Ping Pong! 🏓'); // CronTask[ping] Ping Pong! 🏓
41
+ * }
42
+ * }
43
+ * ```
44
+ */
45
+ declare abstract class CronTask<Options extends CronTask.Options = CronTask.Options> extends Piece<Options, 'cron-tasks'> {
25
46
  job: CronJob<null, CronTask>;
26
47
  constructor(context: CronTask.LoaderContext, options: Options);
27
48
  abstract run(): Awaitable<unknown>;
49
+ /**
50
+ * A helper function to log messages with the `CronTask[${name}]` prefix.
51
+ * @param message The message to include after the prefix
52
+ * @param other Extra parameters to pass to the logger
53
+ * @example
54
+ * this.info('Hello world!'); // CronTask[my-task] Hello world!
55
+ */
28
56
  info(message: string, ...other: unknown[]): void;
57
+ /**
58
+ * A helper function to log messages with the `CronTask[${name}]` prefix.
59
+ * @param message The message to include after the prefix
60
+ * @param other Extra parameters to pass to the logger
61
+ * @example
62
+ * this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!
63
+ */
29
64
  error(message: string, ...other: unknown[]): void;
65
+ /**
66
+ * A helper function to log messages with the `CronTask[${name}]` prefix.
67
+ * @param message The message to include after the prefix
68
+ * @param other Extra parameters to pass to the logger
69
+ * @example
70
+ * this.warn('Something is not right!'); // CronTask[my-task] Something is not right!
71
+ */
30
72
  warn(message: string, ...other: unknown[]): void;
73
+ /**
74
+ * A helper function to log messages with the `CronTask[${name}]` prefix.
75
+ * @param message The message to include after the prefix
76
+ * @param other Extra parameters to pass to the logger
77
+ * @example
78
+ * this.debug('Something is happening!'); // CronTask[my-task] Something is happening!
79
+ */
31
80
  debug(message: string, ...other: unknown[]): void;
81
+ /**
82
+ * A helper function to log messages with the `CronTask[${name}]` prefix.
83
+ * @param message The message to include after the prefix
84
+ * @param other Extra parameters to pass to the logger
85
+ * @example
86
+ * this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.
87
+ */
32
88
  trace(message: string, ...other: unknown[]): void;
33
89
  }
34
90
  declare namespace CronTask {
35
91
  type Options = Piece.Options & CronJobOptions;
36
92
  /** @deprecated Use {@linkcode LoaderContext} instead. */
37
93
  type Context = LoaderContext;
38
- type LoaderContext = Piece.LoaderContext<"cron-tasks">;
94
+ type LoaderContext = Piece.LoaderContext<'cron-tasks'>;
39
95
  }
40
96
 
41
- declare class CronTaskStore extends Store<CronTask, "cron-tasks"> {
97
+ declare class CronTaskStore extends Store<CronTask, 'cron-tasks'> {
42
98
  constructor();
99
+ /**
100
+ * Loops over all tasks and starts those that are enabled.
101
+ * This gets called automatically when the Client is ready.
102
+ * @returns CronTaskStore
103
+ */
43
104
  startAll(): this;
105
+ /**
106
+ * Loops over all tasks and stops those that are running.
107
+ * @returns CronTaskStore
108
+ */
44
109
  stopAll(): this;
45
110
  set(key: string, value: CronTask): this;
46
111
  delete(key: string): boolean;
112
+ /**
113
+ * Stops all running cron jobs and clears the store.
114
+ * @returns void
115
+ */
47
116
  clear(): void;
48
117
  }
49
118
 
50
119
  declare class CronTaskHandler {
51
- defaultTimezone?: CronTaskHandlerOptions["defaultTimezone"];
52
- disableSentry?: boolean;
120
+ /**
121
+ * The default timezone to use for all cron tasks.
122
+ * You can override this per task, using the timeZone option.
123
+ * @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone
124
+ * @default 'system'
125
+ */
126
+ defaultTimezone: CronTaskHandlerOptions['defaultTimezone'];
127
+ /**
128
+ * The ability to opt-out of instrumenting cron jobs with Sentry.
129
+ * If you don't use Sentry, you can ignore this option.
130
+ * @see https://docs.sentry.io/product/crons/
131
+ * @default false
132
+ */
133
+ disableSentry: boolean;
134
+ /**
135
+ * The Sentry instance to use for instrumenting cron jobs.
136
+ * This is only available when [`@sentry/node`](https://www.npmjs.com/package/@sentry/node)
137
+ * is installed and the {@linkcode disableSentry} option is set to false.
138
+ */
53
139
  sentry?: typeof Sentry;
54
140
  constructor(options?: CronTaskHandlerOptions);
141
+ /**
142
+ * Start all enabled cron jobs.
143
+ * This gets called automatically when the Client is ready.
144
+ */
55
145
  startAll(): void;
146
+ /**
147
+ * Stop all running cron jobs.
148
+ */
56
149
  stopAll(): void;
150
+ /**
151
+ * Get the cron task store.
152
+ */
57
153
  private get store();
58
154
  }
59
155
 
60
- declare module "@sapphire/pieces" {
156
+ declare module '@sapphire/pieces' {
61
157
  interface Container {
62
158
  cron: CronTaskHandler;
63
159
  }
64
160
  interface StoreRegistryEntries {
65
- "cron-tasks": CronTaskStore;
161
+ 'cron-tasks': CronTaskStore;
66
162
  }
67
163
  }
68
- declare module "discord.js" {
164
+ declare module 'discord.js' {
69
165
  interface ClientOptions {
70
166
  cron?: CronTaskHandlerOptions;
71
167
  }
@@ -8,18 +8,45 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
8
8
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
9
9
  var _CronTaskHandler = class _CronTaskHandler {
10
10
  constructor(options) {
11
+ /**
12
+ * The default timezone to use for all cron tasks.
13
+ * You can override this per task, using the timeZone option.
14
+ * @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone
15
+ * @default 'system'
16
+ */
11
17
  __publicField(this, "defaultTimezone");
18
+ /**
19
+ * The ability to opt-out of instrumenting cron jobs with Sentry.
20
+ * If you don't use Sentry, you can ignore this option.
21
+ * @see https://docs.sentry.io/product/crons/
22
+ * @default false
23
+ */
12
24
  __publicField(this, "disableSentry");
25
+ /**
26
+ * The Sentry instance to use for instrumenting cron jobs.
27
+ * This is only available when [`@sentry/node`](https://www.npmjs.com/package/@sentry/node)
28
+ * is installed and the {@linkcode disableSentry} option is set to false.
29
+ */
13
30
  __publicField(this, "sentry");
14
- this.defaultTimezone = options?.defaultTimezone;
15
- this.disableSentry = options?.disableSentry;
31
+ this.defaultTimezone = options?.defaultTimezone ?? "system";
32
+ this.disableSentry = options?.disableSentry ?? false;
16
33
  }
34
+ /**
35
+ * Start all enabled cron jobs.
36
+ * This gets called automatically when the Client is ready.
37
+ */
17
38
  startAll() {
18
39
  this.store.startAll();
19
40
  }
41
+ /**
42
+ * Stop all running cron jobs.
43
+ */
20
44
  stopAll() {
21
45
  this.store.stopAll();
22
46
  }
47
+ /**
48
+ * Get the cron task store.
49
+ */
23
50
  get store() {
24
51
  return framework.container.stores.get("cron-tasks");
25
52
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":["container"],"mappings":";;;;;;;;AAIO,IAAM,gBAAA,GAAN,MAAM,gBAAgB,CAAA;AAAA,EAKzB,YAAY,OAAkC,EAAA;AAJ9C,IAAA,aAAA,CAAA,IAAA,EAAA,iBAAA,CAAA,CAAA;AACA,IAAA,aAAA,CAAA,IAAA,EAAA,eAAA,CAAA,CAAA;AACA,IAAA,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AAGI,IAAA,IAAA,CAAK,kBAAkB,OAAS,EAAA,eAAA,CAAA;AAChC,IAAA,IAAA,CAAK,gBAAgB,OAAS,EAAA,aAAA,CAAA;AAAA,GAClC;AAAA,EAEA,QAAW,GAAA;AACP,IAAA,IAAA,CAAK,MAAM,QAAS,EAAA,CAAA;AAAA,GACxB;AAAA,EAEA,OAAU,GAAA;AACN,IAAA,IAAA,CAAK,MAAM,OAAQ,EAAA,CAAA;AAAA,GACvB;AAAA,EAEA,IAAY,KAAQ,GAAA;AAChB,IAAO,OAAAA,mBAAA,CAAU,MAAO,CAAA,GAAA,CAAI,YAAY,CAAA,CAAA;AAAA,GAC5C;AACJ,CAAA,CAAA;AArB6B,MAAA,CAAA,gBAAA,EAAA,iBAAA,CAAA,CAAA;AAAtB,IAAM,eAAN,GAAA","file":"CronTaskHandler.cjs","sourcesContent":["import { container } from \"@sapphire/framework\";\nimport type { CronTaskHandlerOptions } from \"./types/CronTaskTypes\";\nimport type Sentry from \"@sentry/node\";\n\nexport class CronTaskHandler {\n defaultTimezone?: CronTaskHandlerOptions[\"defaultTimezone\"];\n disableSentry?: boolean;\n sentry?: typeof Sentry;\n\n constructor(options?: CronTaskHandlerOptions) {\n this.defaultTimezone = options?.defaultTimezone;\n this.disableSentry = options?.disableSentry;\n }\n\n startAll() {\n this.store.startAll();\n }\n\n stopAll() {\n this.store.stopAll();\n }\n\n private get store() {\n return container.stores.get(\"cron-tasks\");\n }\n}\n"]}
1
+ {"version":3,"sources":["../../../src/lib/CronTaskHandler.ts"],"names":["container"],"mappings":";;;;;;;;AAIO,IAAM,gBAAA,GAAN,MAAM,gBAAgB,CAAA;AAAA,EAwBrB,YAAY,OAAkC,EAAA;AAjBrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,iBAAA,CAAA,CAAA;AAQP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,eAAA,CAAA,CAAA;AAOP;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AAGN,IAAK,IAAA,CAAA,eAAA,GAAkB,SAAS,eAAmB,IAAA,QAAA,CAAA;AACnD,IAAK,IAAA,CAAA,aAAA,GAAgB,SAAS,aAAiB,IAAA,KAAA,CAAA;AAAA,GAChD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,QAAW,GAAA;AACjB,IAAA,IAAA,CAAK,MAAM,QAAS,EAAA,CAAA;AAAA,GACrB;AAAA;AAAA;AAAA;AAAA,EAKO,OAAU,GAAA;AAChB,IAAA,IAAA,CAAK,MAAM,OAAQ,EAAA,CAAA;AAAA,GACpB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAY,KAAQ,GAAA;AACnB,IAAO,OAAAA,mBAAA,CAAU,MAAO,CAAA,GAAA,CAAI,YAAY,CAAA,CAAA;AAAA,GACzC;AACD,CAAA,CAAA;AAlD6B,MAAA,CAAA,gBAAA,EAAA,iBAAA,CAAA,CAAA;AAAtB,IAAM,eAAN,GAAA","file":"CronTaskHandler.cjs","sourcesContent":["import { container } from '@sapphire/framework';\nimport type Sentry from '@sentry/node';\nimport type { CronTaskHandlerOptions } from './types/CronTaskTypes';\n\nexport class CronTaskHandler {\n\t/**\n\t * The default timezone to use for all cron tasks.\n\t * You can override this per task, using the timeZone option.\n\t * @see https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone\n\t * @default 'system'\n\t */\n\tpublic defaultTimezone: CronTaskHandlerOptions['defaultTimezone'];\n\n\t/**\n\t * The ability to opt-out of instrumenting cron jobs with Sentry.\n\t * If you don't use Sentry, you can ignore this option.\n\t * @see https://docs.sentry.io/product/crons/\n\t * @default false\n\t */\n\tpublic disableSentry: boolean;\n\n\t/**\n\t * The Sentry instance to use for instrumenting cron jobs.\n\t * This is only available when [`@sentry/node`](https://www.npmjs.com/package/@sentry/node)\n\t * is installed and the {@linkcode disableSentry} option is set to false.\n\t */\n\tpublic sentry?: typeof Sentry;\n\n\tpublic constructor(options?: CronTaskHandlerOptions) {\n\t\tthis.defaultTimezone = options?.defaultTimezone ?? 'system';\n\t\tthis.disableSentry = options?.disableSentry ?? false;\n\t}\n\n\t/**\n\t * Start all enabled cron jobs.\n\t * This gets called automatically when the Client is ready.\n\t */\n\tpublic startAll() {\n\t\tthis.store.startAll();\n\t}\n\n\t/**\n\t * Stop all running cron jobs.\n\t */\n\tpublic stopAll() {\n\t\tthis.store.stopAll();\n\t}\n\n\t/**\n\t * Get the cron task store.\n\t */\n\tprivate get store() {\n\t\treturn container.stores.get('cron-tasks');\n\t}\n}\n"]}
@@ -8,35 +8,55 @@ var _CronTask = class _CronTask extends pieces.Piece {
8
8
  constructor(context, options) {
9
9
  super(context, options);
10
10
  }
11
+ /**
12
+ * A helper function to log messages with the `CronTask[${name}]` prefix.
13
+ * @param message The message to include after the prefix
14
+ * @param other Extra parameters to pass to the logger
15
+ * @example
16
+ * this.info('Hello world!'); // CronTask[my-task] Hello world!
17
+ */
11
18
  info(message, ...other) {
12
- this.container.logger.info(
13
- `CronTask[${this.name}] ${message}`,
14
- ...other
15
- );
19
+ this.container.logger.info(`CronTask[${this.name}] ${message}`, ...other);
16
20
  }
21
+ /**
22
+ * A helper function to log messages with the `CronTask[${name}]` prefix.
23
+ * @param message The message to include after the prefix
24
+ * @param other Extra parameters to pass to the logger
25
+ * @example
26
+ * this.error('Something went wrong!'); // CronTask[my-task] Something went wrong!
27
+ */
17
28
  error(message, ...other) {
18
- this.container.logger.error(
19
- `CronTask[${this.name}] ${message}`,
20
- ...other
21
- );
29
+ this.container.logger.error(`CronTask[${this.name}] ${message}`, ...other);
22
30
  }
31
+ /**
32
+ * A helper function to log messages with the `CronTask[${name}]` prefix.
33
+ * @param message The message to include after the prefix
34
+ * @param other Extra parameters to pass to the logger
35
+ * @example
36
+ * this.warn('Something is not right!'); // CronTask[my-task] Something is not right!
37
+ */
23
38
  warn(message, ...other) {
24
- this.container.logger.warn(
25
- `CronTask[${this.name}] ${message}`,
26
- ...other
27
- );
39
+ this.container.logger.warn(`CronTask[${this.name}] ${message}`, ...other);
28
40
  }
41
+ /**
42
+ * A helper function to log messages with the `CronTask[${name}]` prefix.
43
+ * @param message The message to include after the prefix
44
+ * @param other Extra parameters to pass to the logger
45
+ * @example
46
+ * this.debug('Something is happening!'); // CronTask[my-task] Something is happening!
47
+ */
29
48
  debug(message, ...other) {
30
- this.container.logger.debug(
31
- `CronTask[${this.name}] ${message}`,
32
- ...other
33
- );
49
+ this.container.logger.debug(`CronTask[${this.name}] ${message}`, ...other);
34
50
  }
51
+ /**
52
+ * A helper function to log messages with the `CronTask[${name}]` prefix.
53
+ * @param message The message to include after the prefix
54
+ * @param other Extra parameters to pass to the logger
55
+ * @example
56
+ * this.trace('Loaded the file.'); // CronTask[my-task] Loaded the file.
57
+ */
35
58
  trace(message, ...other) {
36
- this.container.logger.trace(
37
- `CronTask[${this.name}] ${message}`,
38
- ...other
39
- );
59
+ this.container.logger.trace(`CronTask[${this.name}] ${message}`, ...other);
40
60
  }
41
61
  };
42
62
  __name(_CronTask, "CronTask");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/CronTask.ts"],"names":["Piece"],"mappings":";;;;;;AAKO,IAAe,SAAA,GAAf,MAAe,SAAA,SAEZA,YAA6B,CAAA;AAAA,EAGnC,WAAA,CAAY,SAAiC,OAAkB,EAAA;AAC3D,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA,CAAA;AAAA,GAC1B;AAAA,EAIA,IAAA,CAAK,YAAoB,KAAkB,EAAA;AACvC,IAAA,IAAA,CAAK,UAAU,MAAO,CAAA,IAAA;AAAA,MAClB,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAA,EAAA,EAAK,OAAO,CAAA,CAAA;AAAA,MACjC,GAAG,KAAA;AAAA,KACP,CAAA;AAAA,GACJ;AAAA,EAEA,KAAA,CAAM,YAAoB,KAAkB,EAAA;AACxC,IAAA,IAAA,CAAK,UAAU,MAAO,CAAA,KAAA;AAAA,MAClB,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAA,EAAA,EAAK,OAAO,CAAA,CAAA;AAAA,MACjC,GAAG,KAAA;AAAA,KACP,CAAA;AAAA,GACJ;AAAA,EAEA,IAAA,CAAK,YAAoB,KAAkB,EAAA;AACvC,IAAA,IAAA,CAAK,UAAU,MAAO,CAAA,IAAA;AAAA,MAClB,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAA,EAAA,EAAK,OAAO,CAAA,CAAA;AAAA,MACjC,GAAG,KAAA;AAAA,KACP,CAAA;AAAA,GACJ;AAAA,EAEA,KAAA,CAAM,YAAoB,KAAkB,EAAA;AACxC,IAAA,IAAA,CAAK,UAAU,MAAO,CAAA,KAAA;AAAA,MAClB,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAA,EAAA,EAAK,OAAO,CAAA,CAAA;AAAA,MACjC,GAAG,KAAA;AAAA,KACP,CAAA;AAAA,GACJ;AAAA,EAEA,KAAA,CAAM,YAAoB,KAAkB,EAAA;AACxC,IAAA,IAAA,CAAK,UAAU,MAAO,CAAA,KAAA;AAAA,MAClB,CAAY,SAAA,EAAA,IAAA,CAAK,IAAI,CAAA,EAAA,EAAK,OAAO,CAAA,CAAA;AAAA,MACjC,GAAG,KAAA;AAAA,KACP,CAAA;AAAA,GACJ;AACJ,CAAA,CAAA;AA3CuC,MAAA,CAAA,SAAA,EAAA,UAAA,CAAA,CAAA;AAFhC,IAAe,QAAf,GAAA","file":"CronTask.cjs","sourcesContent":["import { Piece } from \"@sapphire/pieces\";\nimport type { CronJob } from \"cron\";\nimport type { CronJobOptions } from \"../types/CronTaskTypes\";\nimport type { Awaitable } from \"@sapphire/framework\";\n\nexport abstract class CronTask<\n Options extends CronTask.Options = CronTask.Options,\n> extends Piece<Options, \"cron-tasks\"> {\n declare job: CronJob<null, CronTask>;\n\n constructor(context: CronTask.LoaderContext, options: Options) {\n super(context, options);\n }\n\n abstract run(): Awaitable<unknown>;\n\n info(message: string, ...other: unknown[]) {\n this.container.logger.info(\n `CronTask[${this.name}] ${message}`,\n ...other,\n );\n }\n\n error(message: string, ...other: unknown[]) {\n this.container.logger.error(\n `CronTask[${this.name}] ${message}`,\n ...other,\n );\n }\n\n warn(message: string, ...other: unknown[]) {\n this.container.logger.warn(\n `CronTask[${this.name}] ${message}`,\n ...other,\n );\n }\n\n debug(message: string, ...other: unknown[]) {\n this.container.logger.debug(\n `CronTask[${this.name}] ${message}`,\n ...other,\n );\n }\n\n trace(message: string, ...other: unknown[]) {\n this.container.logger.trace(\n `CronTask[${this.name}] ${message}`,\n ...other,\n );\n }\n}\n\nexport namespace CronTask {\n export type Options = Piece.Options & CronJobOptions;\n /** @deprecated Use {@linkcode LoaderContext} instead. */\n export type Context = LoaderContext;\n export type LoaderContext = Piece.LoaderContext<\"cron-tasks\">;\n}\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,CAAA;AAAA,GACvB;AAAA;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,CAAA;AAAA,GACzE;AAAA;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,CAAA;AAAA,GAC1E;AAAA;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,CAAA;AAAA,GACzE;AAAA;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,CAAA;AAAA,GAC1E;AAAA;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,CAAA;AAAA,GAC1E;AACD,CAAA,CAAA;AA/DyH,MAAA,CAAA,SAAA,EAAA,UAAA,CAAA,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\tpublic declare 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"]}