aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-02-10 21:05:01 -0500
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-02-10 21:05:01 -0500
commit728e1a473c9208aeb15e5733b59d730793df6b21 (patch)
tree1d48d494dca7c2ddd3a715283dcc49c00754a65a
parentaf9e5a0fe36442035c87b843fc2f17cf7c80a675 (diff)
downloadtanzanite-728e1a473c9208aeb15e5733b59d730793df6b21.tar.gz
tanzanite-728e1a473c9208aeb15e5733b59d730793df6b21.tar.bz2
tanzanite-728e1a473c9208aeb15e5733b59d730793df6b21.zip
feat: testing modals
-rw-r--r--src/commands/dev/test.ts69
-rw-r--r--src/lib/extensions/discord-akairo/BushClient.ts3
-rw-r--r--src/listeners/client/interactionCreate.ts1
-rw-r--r--src/listeners/ws/INTERACTION_CREATE.ts25
4 files changed, 97 insertions, 1 deletions
diff --git a/src/commands/dev/test.ts b/src/commands/dev/test.ts
index b53b2d8..669001f 100644
--- a/src/commands/dev/test.ts
+++ b/src/commands/dev/test.ts
@@ -1,10 +1,13 @@
import { BushCommand, ButtonPaginator, Shared, type BushMessage } from '#lib';
+// eslint-disable-next-line node/file-extension-in-import
+import { Routes } from 'discord-api-types/rest/v9';
import {
ActionRow,
ActionRowComponent,
ButtonComponent,
ButtonStyle,
Embed,
+ GatewayDispatchEvents,
type ApplicationCommand,
type Collection
} from 'discord.js';
@@ -143,6 +146,72 @@ export default class TestCommand extends BushCommand {
row.badWords = badWords;
await row.save();
return await message.util.reply(`${util.emojis.success} Synced automod.`);
+ } else if (['modal'].includes(args?.feature?.toLowerCase())) {
+ const m = await message.util.reply({
+ content: 'Click for modal',
+ components: [
+ new ActionRow().addComponents(
+ new ButtonComponent().setStyle(ButtonStyle.Primary).setLabel('Modal').setCustomId('test;modal')
+ )
+ ]
+ });
+
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
+ client.ws.on(GatewayDispatchEvents.InteractionCreate, async (i: any) => {
+ if (i?.data?.custom_id !== 'test;modal' || i?.data?.component_type !== 2) return;
+ if (i?.message?.id !== m.id) return;
+
+ const text = { type: 4, style: 1, min_length: 1, max_length: 4000, required: true };
+
+ await this.client.rest.post(Routes.interactionCallback(i.id, i.token), {
+ body: {
+ type: 9,
+ data: {
+ custom_id: 'test;login',
+ title: 'Login (real)',
+ components: [
+ {
+ type: 1,
+ components: [
+ {
+ ...text,
+ custom_id: 'test;login;email',
+ label: 'Email',
+ placeholder: 'Email'
+ }
+ ]
+ },
+ {
+ type: 1,
+ components: [
+ {
+ ...text,
+ custom_id: 'test;login;password',
+ label: 'Password',
+ placeholder: 'Password'
+ }
+ ]
+ },
+ {
+ type: 1,
+ components: [
+ {
+ ...text,
+ custom_id: 'test;login;2fa',
+ label: 'Enter Discord Auth Code',
+ min_length: 6,
+ max_length: 6,
+ placeholder: '6-digit authentication code'
+ }
+ ]
+ }
+ ]
+ }
+ }
+ });
+ });
+
+ return;
}
return await message.util.reply(responses[Math.floor(Math.random() * responses.length)]);
}
diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts
index 748f451..8dcbf05 100644
--- a/src/lib/extensions/discord-akairo/BushClient.ts
+++ b/src/lib/extensions/discord-akairo/BushClient.ts
@@ -355,7 +355,8 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
process,
stdin: rl,
gateway: this.ws,
- rest: this.rest
+ rest: this.rest,
+ ws: this.ws
});
this.commandHandler.resolver.addTypes({
duration,
diff --git a/src/listeners/client/interactionCreate.ts b/src/listeners/client/interactionCreate.ts
index 6543d03..636bb6e 100644
--- a/src/listeners/client/interactionCreate.ts
+++ b/src/listeners/client/interactionCreate.ts
@@ -11,6 +11,7 @@ export default class InteractionCreateListener extends BushListener {
public override async exec(...[interaction]: BushClientEvents['interactionCreate']) {
if (!interaction) return;
+ if ('customId' in interaction && (interaction as any)['customId'].startsWith('test')) return;
void client.console.verbose(
'interactionVerbose',
`An interaction of type <<${BushInteractionType[interaction.type]}>> was received from <<${interaction.user.tag}>>.`
diff --git a/src/listeners/ws/INTERACTION_CREATE.ts b/src/listeners/ws/INTERACTION_CREATE.ts
new file mode 100644
index 0000000..a7c8a45
--- /dev/null
+++ b/src/listeners/ws/INTERACTION_CREATE.ts
@@ -0,0 +1,25 @@
+import { BushListener } from '#lib';
+// eslint-disable-next-line node/file-extension-in-import
+import { GatewayDispatchEvents, Routes } from 'discord-api-types/v9';
+
+export default class WsInteractionCreateListener extends BushListener {
+ public constructor() {
+ super('wsInteractionCreate', {
+ emitter: 'ws',
+ event: GatewayDispatchEvents.InteractionCreate,
+ category: 'ws'
+ });
+ }
+
+ public override async exec(interaction: any) {
+ // console.dir(interaction);
+
+ if (interaction.type === 5) {
+ await this.client.rest.post(Routes.interactionCallback(interaction.id, interaction.token), {
+ body: {
+ type: 6
+ }
+ });
+ }
+ }
+}