modal/module example

This commit is contained in:
Jacob Nguyen
2024-05-24 01:29:52 -05:00
parent bec379b882
commit a055d098eb
11 changed files with 99 additions and 30 deletions

View File

@@ -7,8 +7,8 @@ title: "@sern/handler"
## Namespaces
- [Presence](/v3/api/namespaces/presence/readme/)
- [Sern](/v3/api/namespaces/sern/readme/)
- [Presence](/v3/api/namespacespresence/readme/)
- [Sern](/v3/api/namespacessern/readme/)
## Enumerations

View File

@@ -24,7 +24,7 @@ array of dependencies, in the same order of keys provided
## Since
3.0.0
The plural version of [Service](../../../../../../v3/api/functions/service)
The plural version of [Service](../../../../../../../../v3/api/functions/service)
## Source

View File

@@ -8,7 +8,7 @@ title: "discordEvent"
> **discordEvent**\<`T`\>(`mod`): [`EventModule`](/v3/api/type-aliases/eventmodule/)
Create event modules from discord.js client events,
This is an [eventModule](../../../../../../v3/api/functions/eventmodule) for discord events,
This is an [eventModule](../../../../../../../../v3/api/functions/eventmodule) for discord events,
where typings can be very bad.
## Type parameters

View File

@@ -0,0 +1,21 @@
---
editUrl: false
next: false
prev: false
title: "Presence"
---
## Index
### Interfaces
- [Result](/v3/api/namespacespresenceinterfaces/result/)
### Type Aliases
- [Config](/v3/api/namespacespresencetype-aliases/config/)
### Functions
- [module](/v3/api/namespacespresencefunctions/module/)
- [of](/v3/api/namespacespresencefunctions/of/)

View File

@@ -5,7 +5,7 @@ prev: false
title: "module"
---
> **module**\<`T`\>(`conf`): [`Config`](/v3/api/namespaces/presence/type-aliases/config/)\<`T`\>
> **module**\<`T`\>(`conf`): [`Config`](/v3/api/namespacespresencetype-aliases/config/)\<`T`\>
A small wrapper to provide type inference.
Create a Presence module which **MUST** be put in a file called presence.(language-extension)
@@ -17,11 +17,11 @@ adjacent to the file where **Sern.init** is CALLED.
## Parameters
**conf**: [`Config`](/v3/api/namespaces/presence/type-aliases/config/)\<`T`\>
**conf**: [`Config`](/v3/api/namespacespresencetype-aliases/config/)\<`T`\>
## Returns
[`Config`](/v3/api/namespaces/presence/type-aliases/config/)\<`T`\>
[`Config`](/v3/api/namespacespresencetype-aliases/config/)\<`T`\>
## Source

View File

@@ -13,7 +13,7 @@ Create a Presence body which can be either:
## Parameters
**root**: `Omit`\<[`Result`](/v3/api/namespaces/presence/interfaces/result/), `"repeat"` \| `"onRepeat"`\>
**root**: `Omit`\<[`Result`](/v3/api/namespacespresenceinterfaces/result/), `"repeat"` \| `"onRepeat"`\>
## Returns
@@ -21,7 +21,7 @@ Create a Presence body which can be either:
### once()
> **once**: () => `Omit`\<[`Result`](/v3/api/namespaces/presence/interfaces/result/), `"repeat"` \| `"onRepeat"`\>
> **once**: () => `Omit`\<[`Result`](/v3/api/namespacespresenceinterfaces/result/), `"repeat"` \| `"onRepeat"`\>
#### Example
@@ -37,7 +37,7 @@ Presence
#### Returns
`Omit`\<[`Result`](/v3/api/namespaces/presence/interfaces/result/), `"repeat"` \| `"onRepeat"`\>
`Omit`\<[`Result`](/v3/api/namespacespresenceinterfaces/result/), `"repeat"` \| `"onRepeat"`\>
### repeated()

View File

@@ -29,15 +29,15 @@ title: "Result"
### onRepeat()?
> `optional` **onRepeat**: (`previous`) => [`Result`](/v3/api/namespaces/presence/interfaces/result/)
> `optional` **onRepeat**: (`previous`) => [`Result`](/v3/api/namespacespresenceinterfaces/result/)
#### Parameters
**previous**: [`Result`](/v3/api/namespaces/presence/interfaces/result/)
**previous**: [`Result`](/v3/api/namespacespresenceinterfaces/result/)
#### Returns
[`Result`](/v3/api/namespaces/presence/interfaces/result/)
[`Result`](/v3/api/namespacespresenceinterfaces/result/)
#### Source

View File

@@ -15,7 +15,7 @@ title: "Config"
### execute()
> **execute**: (...`v`) => [`Result`](/v3/api/namespaces/presence/interfaces/result/)
> **execute**: (...`v`) => [`Result`](/v3/api/namespacespresenceinterfaces/result/)
#### Parameters
@@ -23,7 +23,7 @@ title: "Config"
#### Returns
[`Result`](/v3/api/namespaces/presence/interfaces/result/)
[`Result`](/v3/api/namespacespresenceinterfaces/result/)
### inject?

View File

@@ -0,0 +1,12 @@
---
editUrl: false
next: false
prev: false
title: "Sern"
---
## Index
### Functions
- [init](/v3/api/namespacessernfunctions/init/)

View File

@@ -7,7 +7,7 @@ title: "SernOptionsData"
> **SernOptionsData**: [`SernSubCommandData`](/v3/api/interfaces/sernsubcommanddata/) \| [`SernSubCommandGroupData`](/v3/api/interfaces/sernsubcommandgroupdata/) \| `APIApplicationCommandBasicOption` \| [`SernAutocompleteData`](/v3/api/interfaces/sernautocompletedata/)
Type that replaces autocomplete with [SernAutocompleteData](../../../../../../v3/api/interfaces/sernautocompletedata)
Type that replaces autocomplete with [SernAutocompleteData](../../../../../../../../v3/api/interfaces/sernautocompletedata)
## Source

View File

@@ -8,7 +8,7 @@ sern operates with modules. At its core, Modules contain a `type` field and `exe
executing.
### Modules
we'll walk you through creating your first command module.
We'll walk you through creating your first command module.
If you installed a new project via the CLI, your file should be here:
@@ -36,6 +36,9 @@ export default commandModule({
Run `sern commands publish` so discord registers it to your application correctly.
:::
import { Tabs, TabItem } from '@astrojs/starlight/components';
## Modal
So, lets say you want to make a command module that listens to modals.
@@ -43,17 +46,50 @@ So, lets say you want to make a command module that listens to modals.
Keep in mind, you'll need to send a modal with a custom id of `dm-me`. This example below is the response to a modal being sent.
:::
```js title=src/commands/dm-me.js
import { CommandType, commandModule } from "@sern/handler";
export default commandModule({
type: CommandType.Modal,
async execute(modal) {
const value = modal.fields.getTextInputValue("message");
modal.client.users
.fetch("182326315813306368")
.then(usr => usr.send(value + ` from ${modal.user}`));
modal.reply({ ephemeral: true, content: "Sent" });
},
});
```
<Tabs syncKey="language-preference">
<TabItem value="js" label="Send Modal">
```js title="src/commands/ping.js"
import { CommandType, commandModule } from "@sern/handler";
import { ModalBuilder, ActionRowBuilder } from 'discord.js';
export default commandModule({
type: CommandType.Slash,
description: "A ping command",
execute: async (ctx, sdt) => {
const modal = new ModalBuilder()
.setCustomId('dm-me')
.setTitle('My Modal');
const hobbiesInput = new TextInputBuilder()
.setCustomId('dmmsg')
.setLabel("What do you want to send to me")
.setStyle(TextInputStyle.Paragraph);
// An action row only holds one text input,
const row = new ActionRowBuilder().addComponents(hobbiesInput);
// Add inputs to the modal
modal.addComponents(row);
await ctx.interaction.showModal(modal);
await ctx.reply("Pong 🏓");
},
});
```
</TabItem>
<TabItem value="ts" label="Modal Listener">
```ts title="src/commands/dm-me.js"
import { CommandType, commandModule } from "@sern/handler";
export default commandModule({
type: CommandType.Modal,
async execute(modal) {
const value = modal.fields.getTextInputValue("message");
modal.client.users
.fetch("182326315813306368")
.then(usr => usr.send(value + ` from ${modal.user}`));
modal.reply({ ephemeral: true, content: "Sent" });
},
});
```
</TabItem>
</Tabs>