Skip to content

Commit

Permalink
removed button command & did general cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Sans3108 committed Apr 5, 2024
1 parent df6274a commit 57fc640
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 357 deletions.
Empty file added .env.example
Empty file.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"@babel/cli": "^7.24.1",
"@types/node": "20.10.0",
"babel-plugin-root-import": "^6.6.0",
"babel-watch": "^7.8.1",
"prettier": "3.2.5"
}
}
533 changes: 227 additions & 306 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ log('setup', 'Logger loaded!');
//#region Environment variables
log('setup', 'Loading environment variables...');

import { checkEnv } from '@scripts/checkEnv.js';
import { checkEnv } from 'utils/functions/checkEnv.js';
import 'dotenv/config';

try {
Expand Down
47 changes: 1 addition & 46 deletions src/classes/client/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ export enum CommandGroup {
export enum CommandType {
chatInput,
messageContext,
userContext,
button
userContext
}

export interface CommandOptionsMetadata {
Expand Down Expand Up @@ -284,53 +283,9 @@ export class UserContextCommand extends BaseCommand {
}
//#endregion

//#region Button Command
export interface ButtonCommandOptions extends BaseCommandOptions {
execute: (interaction: ButtonInteraction, client: CustomClient) => Promise<boolean>;
}

export class ButtonCommand extends BaseCommand {
protected readonly execute: (interaction: ButtonInteraction, client: CustomClient) => Promise<boolean>;

public readonly type: CommandType = CommandType.button;

constructor(options: ButtonCommandOptions) {
super(options);
this.execute = options.execute;
}

public async run(interaction: ButtonInteraction): Promise<void> {
if (this.developer && !developerIds.includes(interaction.user.id)) {
log('commands', `${c(interaction.user.username, colors.user.name)} (${c(interaction.user.id, colors.user.id)}) tried to use developer command ${loggedCommand(this)} but is not a developer.`);

await interaction.reply({
embeds: [emb('error', `You are not allowed to use the ${this} command. This incident was logged.`)],
ephemeral: true
});
return;
}

const result = await this.handleCooldown(interaction, this.execute);

const client = interaction.client as CustomClient;

if (client.options.logCommandUses) {
const res = Object.keys(CommandRunResult).find(key => CommandRunResult[key as keyof typeof CommandRunResult] === result)!;

log('commands', `${c(interaction.user.username, colors.user.name)} (${c(interaction.user.id, colors.user.id)}) used ${loggedCommand(this)} ${c(this.name, colors.command.name)} with result: ${res}`);
}
}

toString() {
return `\`~ ${this.name}\``;
}
}
//#endregion

export abstract class Command {
public static ChatInput = ChatInputCommand;
public static MessageContext = MessageContextCommand;
public static UserContext = UserContextCommand;
public static Button = ButtonCommand;
}
// gyuildonly alwayts
3 changes: 3 additions & 0 deletions src/common/log.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// The purpose of this file is to customize the custom Logger defined in src/classes/Logger
// and to export a function that can be easily used to log different things

import { Log, LogLayerTab, LogTag, ValidLogTagNames } from '@classes/Logger.js';
import { colors, spacerChar, tagEndEdge, tagStartEdge } from '@common/constants.js';

Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions src/utils/functions/loggedCommand.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { ButtonCommand, ChatInputCommand, CommandType, MessageContextCommand, UserContextCommand } from '@classes/client/Command';
import { ChatInputCommand, CommandType, MessageContextCommand, UserContextCommand } from '@classes/client/Command';
import { colors } from '@common/constants';
import { c } from '@log';

export function loggedCommand(command: ButtonCommand | ChatInputCommand | UserContextCommand | MessageContextCommand) {
export function loggedCommand(command: ChatInputCommand | UserContextCommand | MessageContextCommand) {
const symbol =
command.type === CommandType.chatInput ? '/'
: command.type === CommandType.messageContext || command.type === CommandType.userContext ? '*'
: command.type === CommandType.button ? '~'
: '?';

const coloredSymbol = c(symbol, colors.command.symbol);
Expand Down

0 comments on commit 57fc640

Please sign in to comment.