From 400a58d4eb60de44fd1f11e457ac24c0ff021f7d Mon Sep 17 00:00:00 2001 From: Kovacs Alex Date: Sat, 1 Aug 2020 15:14:33 +0300 Subject: [PATCH] feat: implement documentation for tasks --- src/lib/structures/Task.ts | 6 ++++- tutorials/creatingTasks.md | 51 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tutorials/creatingTasks.md diff --git a/src/lib/structures/Task.ts b/src/lib/structures/Task.ts index 9bb623cc..cfc3e119 100644 --- a/src/lib/structures/Task.ts +++ b/src/lib/structures/Task.ts @@ -3,14 +3,18 @@ import { BasePool } from './Pools/Base/BasePool'; import { BasePiece, BasePieceOptions } from './BasePiece'; /** + * [[include:creatingTasks.md]] * @abstract */ export class Task extends BasePiece { + public cron: string; + constructor(client: MoonlightClient, pool: BasePool, options: TaskOptions) { super(client, pool, options); + this.cron = options.cron; } } interface TaskOptions extends BasePieceOptions { - + cron: string; } \ No newline at end of file diff --git a/tutorials/creatingTasks.md b/tutorials/creatingTasks.md new file mode 100644 index 00000000..5485ba9a --- /dev/null +++ b/tutorials/creatingTasks.md @@ -0,0 +1,51 @@ +## Creating tasks + +A task is a piece of code that runs periodically. Currently, tasks can only be repetitive, using a cron! + +For creating a cron, you can head over to [crontab.guru](https://crontab.guru) - we also support the non-standard's! (@yearly, @annually, @monthly, @weekly, @daily and @hourly) + +To get started with tasks, just add a file in your `tasks` folder and use the following example for JavaScript: + +```js +const { Task } = require('@penfoldium/moonlight'); + +module.exports = class extends Task { + constructor(...args) { + super(...args, { + cron: '* * * * *' + }) + } + + run() { + + } + + // This function runs when the bot is first started + init() { + + } +} +``` + +or the following for TypeScript: + +```ts +import { Task, MoonlightClient, BasePool } from '@penfoldium/moonlight'; + +export default class extends Event { + constructor(client: MoonlightClient, pool: BasePool) { + super(client, pool, { + cron: '* * * * *' + }) + } + + public run() { + + } + + // This function runs when the bot is first started + public init() { + + } +} +``` \ No newline at end of file