This repository was archived by the owner on Apr 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
update(CustomEvent,Summary), feat($eventData,$eventEmit) #147
Open
USERSATOSHI
wants to merge
2
commits into
aoijs:v5
Choose a base branch
from
USERSATOSHI:CustomEvents
base: v5
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -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: | ||
USERSATOSHI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
[**`$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 | ||
|
||
<table> | ||
<tr> | ||
<th>Type</th> | ||
<td>Bot</td> | ||
</tr> | ||
<tr> | ||
<th>Description</th> | ||
<td>aoi.js' Bot Class</td> | ||
</tr> | ||
<tr> | ||
<th>Required</th> | ||
<td>yes</td> | ||
</tr> | ||
<tr> | ||
<th>Default</th> | ||
<td>N/A</td> | ||
</tr> | ||
</table> | ||
|
||
## Basic Setup | ||
|
||
As example: | ||
|
||
```javascript | ||
USERSATOSHI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
* 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] | ||
` | ||
}) | ||
``` | ||
|
This file contains hidden or 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,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 | ||
<CustomEvent>.command({ | ||
name: "eventData", | ||
listen: "eventName", | ||
code: ` | ||
$eventData[[0]] | ||
` | ||
}); | ||
``` | ||
|
||
[^1]: [Check CustomEvent Docs for more info](../advanced-guides/custom-events.md) |
This file contains hidden or 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,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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.