Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Commit

Permalink
feat: implement documentation for tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
alexthemaster committed Aug 1, 2020
1 parent 3a9f392 commit 400a58d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/structures/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import { BasePool } from './Pools/Base/BasePool';
import { BasePiece, BasePieceOptions } from './BasePiece';

/**
* [[include:creatingTasks.md]]
* @abstract
*/
export class Task extends BasePiece<Task> {
public cron: string;

constructor(client: MoonlightClient, pool: BasePool<string, Task>, options: TaskOptions) {
super(client, pool, options);
this.cron = options.cron;
}
}

interface TaskOptions extends BasePieceOptions {

cron: string;
}
51 changes: 51 additions & 0 deletions tutorials/creatingTasks.md
Original file line number Diff line number Diff line change
@@ -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<string, Task>) {
super(client, pool, {
cron: '* * * * *'
})
}

public run() {

}

// This function runs when the bot is first started
public init() {

}
}
```

0 comments on commit 400a58d

Please sign in to comment.