From ec93b624a881b82f0dab79ec3a67df9b5bc24ce1 Mon Sep 17 00:00:00 2001 From: Ayaka Date: Fri, 29 Jul 2022 00:47:49 +0530 Subject: [PATCH 1/2] update(CustomEvent,Summary), feat($eventData,$eventEmit) --- src/SUMMARY.md | 2 + src/advanced-guides/custom-events.md | 83 +++++++++++++++++++++------- src/functions/usdeventdata.md | 34 ++++++++++++ src/functions/usdeventemit.md | 34 ++++++++++++ 4 files changed, 133 insertions(+), 20 deletions(-) create mode 100644 src/functions/usdeventdata.md create mode 100644 src/functions/usdeventemit.md 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..7f1c3748 100644 --- a/src/advanced-guides/custom-events.md +++ b/src/advanced-guides/custom-events.md @@ -1,30 +1,73 @@ # 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: +aoi.js has `CustomEvent` class to add custom events to aoi.js that will execute a cmd for that event , whenever the event is emitted. -```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 +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: ```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 { CustomEvent,Bot } = require("aoi.js"); + +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 From 4f9fd891be288b05a173828eef0d119a7979344b Mon Sep 17 00:00:00 2001 From: Ayaka Date: Fri, 19 Aug 2022 18:38:49 +0530 Subject: [PATCH 2/2] changes according to review --- src/advanced-guides/custom-events.md | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/advanced-guides/custom-events.md b/src/advanced-guides/custom-events.md index 7f1c3748..e7090337 100644 --- a/src/advanced-guides/custom-events.md +++ b/src/advanced-guides/custom-events.md @@ -1,8 +1,8 @@ # Custom Events -aoi.js has `CustomEvent` class to add custom events to aoi.js that will execute a cmd for that event , whenever the event is emitted. +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: +This adds 2 new functions: [**`$eventData`**](../functions/usdeventdata.md) and [**`$eventEmit`**](../functions/usdeventemit.md) @@ -37,9 +37,8 @@ const event : CustomEvent = new CustomEvent( ## Basic Setup - -```javascript -const { CustomEvent,Bot } = require("aoi.js"); +```js +const { CustomEvent , Bot } = require("aoi.js"); const bot = new Bot({ token : "DISCORD BOT TOKEN", @@ -50,22 +49,20 @@ const bot = new Bot({ 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]] - ] + code:` + $log[ Pain Event Was Executed By $eventData[[0]] ] ` }); bot.command({ name: "emit-pain", - code: - ` + code:` $eventEmit[pain;$username] ` })