Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

update(CustomEvent,Summary), feat($eventData,$eventEmit) #147

Open
wants to merge 2 commits into
base: v5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
83 changes: 63 additions & 20 deletions src/advanced-guides/custom-events.md
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:

[**`$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
/**
* 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]
`
})
```

34 changes: 34 additions & 0 deletions src/functions/usdeventdata.md
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)
34 changes: 34 additions & 0 deletions src/functions/usdeventemit.md
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)