Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/webserver/banshare.ts
  • Loading branch information
IThundxr committed Dec 28, 2023
2 parents 7d579b1 + 222b026 commit f64081d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
14 changes: 6 additions & 8 deletions src/handlers/button.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ import {
} from 'discord.js';
import { Handler } from '..';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const buttonMap = new Map<string, Button<any>>();

export class Button<ArgsType> {
id: string;
_onPress?: (interaction: ButtonInteraction, args: ArgsType) => unknown;
constructor(
id: string,
onPress: (
interaction: ButtonInteraction,
args: ArgsType
) => unknown
onPress: (interaction: ButtonInteraction, args: ArgsType) => unknown
) {
this.id = id;
if (buttonMap.has(id)) console.error(`Button ${id} is already defined`);
Expand All @@ -38,7 +36,7 @@ export class Button<ArgsType> {
}

export const buttonHandler: Handler = (client) => {
client.on(Events.InteractionCreate, async (interaction:Interaction) => {
client.on(Events.InteractionCreate, async (interaction: Interaction) => {
if (!interaction.isButton()) return;
const data = JSON.parse(interaction.customId);
const args = data.args;
Expand All @@ -48,10 +46,10 @@ export const buttonHandler: Handler = (client) => {
if (!button) return;

if (!button._onPress) return;
try{
try {
button._onPress(interaction, args);
}catch{
interaction.reply("error while executing")
} catch {
interaction.reply('error while executing');
}
});
};
3 changes: 1 addition & 2 deletions src/webserver/banshare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ import { Button } from '../handlers/button.handler';

const banButton = new Button(
'ban',
async (interaction, data:{userId:string}) => {
async (interaction, data: { userId: string }) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// .has exists, just ts doesnt believe it
if (!interaction.member?.permissions.has(PermissionsBitField.Flags.BanMembers)) {
return await interaction.reply({content: "You do not have permission to ban this user", ephemeral: true})
}

const reason =
'simulated banshare: ' +
(interaction.message.embeds[0].fields[3].value ??
Expand Down

0 comments on commit f64081d

Please sign in to comment.