mirror of
https://github.com/nx-bat/discordbot-ng.git
synced 2026-11-11 07:13:37 -05:00
(buttons): Hook up buttons. Pre-testing.
This commit is contained in:
@@ -5,7 +5,7 @@ import { Button } from '../types';
|
||||
class ClaimTicketButton implements Button<Client> {
|
||||
id = 'claim-ticket';
|
||||
|
||||
async execute(context: Client<boolean>, interaction: ButtonInteraction, ...args: any[]): Promise<void> {
|
||||
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
|
||||
if (!interaction.inGuild()) return;
|
||||
await interaction.deferReply({ flags: [MessageFlags.Ephemeral] });
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Button } from '../types';
|
||||
class CloseModTicketButton implements Button<Client> {
|
||||
id = 'close-mod-ticket';
|
||||
|
||||
async execute(context: Client<boolean>, interaction: ButtonInteraction, ...args: any[]): Promise<void> {
|
||||
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
|
||||
if (!interaction.inGuild()) return;
|
||||
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Button } from '../types';
|
||||
class CloseTicketButton implements Button<Client> {
|
||||
id = 'close-ticket';
|
||||
|
||||
async execute(context: Client<boolean>, interaction: ButtonInteraction, ...args: any[]): Promise<void> {
|
||||
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
|
||||
if (!interaction.inGuild()) return;
|
||||
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Button } from '../types';
|
||||
class DevWatchButton implements Button<Client> {
|
||||
id = 'dev-watch';
|
||||
|
||||
async execute(context: Client<boolean>, interaction: ButtonInteraction, ...args: any[]): Promise<void> {
|
||||
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
|
||||
if (!interaction.inGuild()) return;
|
||||
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import claimTicket from "./claimTicket";
|
||||
import closeModTicket from "./closeModTicket";
|
||||
import closeTicket from "./closeTicket";
|
||||
import devWatch from "./devWatch";
|
||||
import noteNext from "./noteNext";
|
||||
import notePrevious from "./notePrevious";
|
||||
import openTicketForReportedMessage from "./openTicketForReportedMessage";
|
||||
import privateHelp from "./privateHelp";
|
||||
import recordsNext from "./recordsNext";
|
||||
import recordsPrevious from "./recordsPrevious";
|
||||
import roleButton from "./roleButton";
|
||||
import unclaimTicket from "./unclaimTicket";
|
||||
|
||||
export default [
|
||||
claimTicket,
|
||||
closeModTicket,
|
||||
closeTicket,
|
||||
devWatch,
|
||||
noteNext,
|
||||
notePrevious,
|
||||
openTicketForReportedMessage,
|
||||
privateHelp,
|
||||
recordsNext,
|
||||
recordsPrevious,
|
||||
roleButton,
|
||||
unclaimTicket
|
||||
];
|
||||
+1
-1
@@ -5,7 +5,7 @@ import { createPrivateHelpTicketThread } from '../utils';
|
||||
class OpenTicketForReportedMessageButton implements Button<Client> {
|
||||
id = 'open-ticket-for-reported-message';
|
||||
|
||||
async execute(context: Client<boolean>, interaction: ButtonInteraction, ...args: any[]): Promise<void> {
|
||||
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
|
||||
if (!interaction.inGuild()) return;
|
||||
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||
|
||||
@@ -5,7 +5,7 @@ import { canOpenPrivateHelpTicket, createTextInput } from '../utils';
|
||||
class PrivateHelpButton implements Button<Client> {
|
||||
id = 'private-help';
|
||||
|
||||
async execute(context: Client<boolean>, interaction: ButtonInteraction, ...args: any[]): Promise<void> {
|
||||
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
|
||||
try {
|
||||
if (!await canOpenPrivateHelpTicket(interaction.user.id))
|
||||
throw new Error('You can only have one open ticket at a time that is less than a day old.');
|
||||
@@ -5,7 +5,7 @@ import { Button } from '../types';
|
||||
class RoleButtonButton implements Button<Client> {
|
||||
id = 'role-button';
|
||||
|
||||
async execute(context: Client<boolean>, interaction: ButtonInteraction, ...args: any[]): Promise<void> {
|
||||
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
|
||||
if (!interaction.inGuild()) return;
|
||||
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Button } from '../types';
|
||||
class UnclaimTicketButton implements Button<Client> {
|
||||
id = 'unclaim-ticket';
|
||||
|
||||
async execute(context: Client<boolean>, interaction: ButtonInteraction, ...args: any[]): Promise<void> {
|
||||
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
|
||||
if (!interaction.inGuild()) return;
|
||||
await interaction.deferReply();
|
||||
|
||||
+5
-6
@@ -1,4 +1,5 @@
|
||||
import { Client, GatewayIntentBits, MessageFlags, Partials } from 'discord.js';
|
||||
import buttons from './buttons';
|
||||
import { config } from './config';
|
||||
import events from './events';
|
||||
import { Database } from './shared/Database';
|
||||
@@ -37,7 +38,6 @@ const client = new Client({
|
||||
|
||||
const commands: Handler[] = [];
|
||||
const contextMenus: Handler[] = [];
|
||||
const buttons: Handler[] = [];
|
||||
const modals: Handler[] = [];
|
||||
const menus: Handler[] = [];
|
||||
|
||||
@@ -93,11 +93,12 @@ client.on('interactionCreate', async (interaction) => {
|
||||
const id = interaction.customId.split('_')[0];
|
||||
|
||||
for (const button of buttons) {
|
||||
if (id == button.name) {
|
||||
button.handler(client, interaction, ...interaction.customId.split('_').slice(1));
|
||||
if (button.id != id) continue;
|
||||
|
||||
Promise.resolve((button.execute as (context: Client, ...args: unknown[]) => Promise<void>)(client, ...interaction.customId.split('_').slice(1))
|
||||
.catch(e => console.error('An error occurred while handling a button interaction: ', e)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (interaction.isModalSubmit()) {
|
||||
// Handle modal submissions.
|
||||
const id = interaction.customId.split('_')[0];
|
||||
@@ -126,14 +127,12 @@ client.on('clientReady', async () => {
|
||||
|
||||
await loadHandlersFrom('commands', commands);
|
||||
await loadHandlersFrom('context-menus', contextMenus);
|
||||
await loadHandlersFrom('buttons', buttons);
|
||||
await loadHandlersFrom('modals', modals);
|
||||
await loadHandlersFrom('menus', menus);
|
||||
|
||||
await refreshCommands(client);
|
||||
|
||||
await initIfNecessary(client, commands);
|
||||
await initIfNecessary(client, buttons);
|
||||
await initIfNecessary(client, modals);
|
||||
await initIfNecessary(client, menus);
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -2,5 +2,5 @@ import { ButtonInteraction } from "discord.js";
|
||||
|
||||
export interface Button<Context> {
|
||||
id: string;
|
||||
execute(context: Context, interaction: ButtonInteraction, ...args: any[]): Promise<void>;
|
||||
execute(context: Context, interaction: ButtonInteraction, ...args: any): Promise<void>;
|
||||
}
|
||||
Reference in New Issue
Block a user