diff --git a/src/SUMMARY.md b/src/SUMMARY.md index a462a59c..39bc8a28 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -170,6 +170,8 @@ * [$emojisFromMessage](functions/usdemojisfrommessage.md) * [$error](functions/usderror.md) * [$eval](functions/usdeval.md) + * [$eventData](functions/usdeventdata.md) + * [$eventEmit](functions/usdeventemit.md) * [$exec](functions/usdexec.md) * [$executionTime](functions/usdexecutiontime.md) * [$fetchInvites](functions/usdfetchinvites.md) diff --git a/src/advanced-guides/custom-events.md b/src/advanced-guides/custom-events.md index 52c7dc7a..e7090337 100644 --- a/src/advanced-guides/custom-events.md +++ b/src/advanced-guides/custom-events.md @@ -1,30 +1,70 @@ # Custom Events -Custom events are constructors that will run dbdjs commands everytime an event was executed. All it need is an Event Emitter. As example: - -```javascript -const event = require("events") -const CustomEvent = new event.EventEmitter() -CustomEvent.command({ -name:"call", // A Name for the command, required for now. -listen:"emitted", // A listener that will be executed if the event was called/emitted -channel:"channel id", // A channel id to send the code -code:`Successful Emit was listened` // A code. -}) -CustomEvent.listen("emitted") //Listen to emitted event and execute all commands that have "emitted" as the listen property +aoi.js has `CustomEvent` class to add custom events to aoi.js that will execute a command for that event , whenever the event is emitted. + +This adds 2 new functions: + + [**`$eventData`**](../functions/usdeventdata.md) and [**`$eventEmit`**](../functions/usdeventemit.md) + +## Usage + +```ts +const event : CustomEvent = new CustomEvent( + bot:Bot, +) ``` -If you want to get some data from the event you can use `$eventData[property]` +### bot + + + + + + + + + + + + + + + + + + +
TypeBot
Descriptionaoi.js' Bot Class
Requiredyes
DefaultN/A
+ +## Basic Setup -As example: +```js +const { CustomEvent , Bot } = require("aoi.js"); -```javascript -/** -* If the event data was for example: -* {vote:"Chïwikichu#1007"} -* In code you can use: -*/ -code: `$eventData[vote] has voted` -// It will return: "Chïwikichu#1007 has voted" +const bot = new Bot({ + token : "DISCORD BOT TOKEN", + prefix: "DISCORD BOT PREFIX", + intents: [ "guilds", "guildMessages" ], +}); + +bot.onMessage(); + +const event = new CustomEvent(bot); + +event.listen("pain"); + +event.command({ + name: "this is pain", + listen: "pain", + code:` + $log[ Pain Event Was Executed By $eventData[[0]] ] + ` +}); + +bot.command({ + name: "emit-pain", + code:` + $eventEmit[pain;$username] + ` +}) ``` diff --git a/src/functions/usdeventdata.md b/src/functions/usdeventdata.md new file mode 100644 index 00000000..faa99d9b --- /dev/null +++ b/src/functions/usdeventdata.md @@ -0,0 +1,34 @@ +--- +description: gets emitted event's data. +--- + +# $eventData + +`$eventData` returns emitted event's data. + +### Usage + +```php +$eventData[[index]] +``` + +### Fields + +| Field | Description | Type | Required | +| :--- | :--- | :--- | :--- | +| index | The position of data[^1] | number | yes | + +## Examples + + +```javascript +.command({ + name: "eventData", + listen: "eventName", + code: ` + $eventData[[0]] + ` +}); +``` + +[^1]: [Check CustomEvent Docs for more info](../advanced-guides/custom-events.md) \ No newline at end of file diff --git a/src/functions/usdeventemit.md b/src/functions/usdeventemit.md new file mode 100644 index 00000000..d55051fc --- /dev/null +++ b/src/functions/usdeventemit.md @@ -0,0 +1,34 @@ +--- +description: gets emitted event's data. +--- + +# $eventEmit + +`$eventEmit` returns emitted event's data. + +### Usage + +```php +$eventEmit[eventName;data;data;...] +``` + +### Fields + +| Field | Description | Type | Required | +| :--- | :--- | :--- | :--- | +| name | event to be emitted[^1] | string | yes | +| data | The data to be emitted | string | yes | + +## Examples + + +```javascript +bot.command({ + name: "eventEmit", + code: ` + $eventEmit[eventName;$username] + ` +}); +``` + +[^1]: [Check CustomEvent Docs for more info](../advanced-guides/custom-events.md) \ No newline at end of file