This repository has been archived by the owner on Jan 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement documentation for tasks
- Loading branch information
1 parent
3a9f392
commit 400a58d
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
|
||
} | ||
} | ||
``` |