diff --git a/src/handlers/button.handler.ts b/src/handlers/button.handler.ts index bc1a651..55098cf 100644 --- a/src/handlers/button.handler.ts +++ b/src/handlers/button.handler.ts @@ -2,37 +2,32 @@ import { ButtonBuilder, ButtonInteraction, Events, + Interaction, InteractionButtonComponentData, } from 'discord.js'; import { Handler } from '..'; -import { BaseSchema, Output } from 'valibot'; -import { error } from 'console'; -// eslint-disable-next-line @typescript-eslint/no-explicit-any const buttonMap = new Map>(); -export class Button { +export class Button { id: string; - args?: ArgsType; _onPress?: (interaction: ButtonInteraction, args: ArgsType) => unknown; constructor( id: string, - args: ArgsType, onPress: ( interaction: ButtonInteraction, - args: Output + args: ArgsType ) => unknown ) { this.id = id; if (buttonMap.has(id)) console.error(`Button ${id} is already defined`); buttonMap.set(id, this); this._onPress = onPress; - this.args = args; } button( data: Partial, - args: Output + args: ArgsType ): ButtonBuilder { const button = new ButtonBuilder({ ...data, @@ -43,7 +38,7 @@ export class Button { } export const buttonHandler: Handler = (client) => { - client.on(Events.InteractionCreate, async (interaction) => { + client.on(Events.InteractionCreate, async (interaction:Interaction) => { if (!interaction.isButton()) return; const data = JSON.parse(interaction.customId); const args = data.args; @@ -51,9 +46,12 @@ export const buttonHandler: Handler = (client) => { if (!buttonMap.has(data.id)) return; const button = buttonMap.get(data.id); if (!button) return; - if (!button.args) throw error('No args set in button'); - const parsedArgs = button.args.parse(args); + if (!button._onPress) return; - button._onPress(interaction, parsedArgs); + try{ + button._onPress(interaction, args); + }catch{ + interaction.reply("error while executing") + } }); }; diff --git a/src/webserver/banshare.ts b/src/webserver/banshare.ts index 8c988c8..b9b988c 100644 --- a/src/webserver/banshare.ts +++ b/src/webserver/banshare.ts @@ -11,12 +11,10 @@ import { TextInputBuilder, } from 'discord.js'; import { Button } from '../handlers/button.handler'; -import { string, object } from 'valibot'; const banButton = new Button( 'ban', - object({ userId: string() }), - async (interaction, data) => { + async (interaction, data:{userId:string}) => { const reason = 'aero banshare: ' + (interaction.message.embeds[0].fields[3].value ??