From 91201e6ca1aea42c347f3de5be3e33cd52061fa5 Mon Sep 17 00:00:00 2001 From: Evorp <3vorpgaming@gmail.com> Date: Wed, 11 Oct 2023 15:28:49 -0700 Subject: [PATCH] how has this not been an issue earlier This reverts commit 515c411c3220d07fcb91125d424cd093f07ae64f. --- src/client/automation.ts | 4 ++-- src/client/client.ts | 2 ++ src/commands/bot/shutdown.ts | 17 +++++++++++++++++ src/helpers/functions/errorHandler.ts | 2 +- src/helpers/utility/handleJSON.ts | 2 +- 5 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 src/commands/bot/shutdown.ts diff --git a/src/client/automation.ts b/src/client/automation.ts index 972e6843a..9b27362a5 100644 --- a/src/client/automation.ts +++ b/src/client/automation.ts @@ -22,7 +22,7 @@ export class Automation { if (!this.ticking) return; // polls check: - this.client.polls.each(this.pollCheck); + this.client.polls.each(this.pollCheck.bind(null, this)); }, 1000); // each second // send to uptime kuma (only for production bot) @@ -34,7 +34,7 @@ export class Automation { } } - private pollCheck(p: Poll): void { + private pollCheck(p: Poll) { const poll = new Poll(p); // get methods back if (poll.isTimeout()) { diff --git a/src/client/client.ts b/src/client/client.ts index ea1ad12ba..74a558a8c 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -126,6 +126,8 @@ export class ExtendedClient extends Client { this.loadComponents(); this.loadEvents(); this.loadCollections(); + + this.automation.start(); }); // I know this restarting stuff kinda sucks but you can't guarantee which one is triggered diff --git a/src/commands/bot/shutdown.ts b/src/commands/bot/shutdown.ts new file mode 100644 index 000000000..2cd310fcc --- /dev/null +++ b/src/commands/bot/shutdown.ts @@ -0,0 +1,17 @@ +import { SlashCommand } from "@interfaces"; +import { SlashCommandBuilder, PermissionFlagsBits } from "discord.js"; +import { ChatInputCommandInteraction, EmbedBuilder } from "@client"; + +export const command: SlashCommand = { + data: new SlashCommandBuilder() + .setName("shutdown") + .setDescription("Shuts down the bot.") + .setDefaultMemberPermissions(PermissionFlagsBits.Administrator), + async execute(interaction: ChatInputCommandInteraction) { + if (!interaction.hasPermission("dev")) return; + await interaction.reply({ + embeds: [new EmbedBuilder().setTitle("Shutting down...")], + }); + return process.exit(); + }, +}; diff --git a/src/helpers/functions/errorHandler.ts b/src/helpers/functions/errorHandler.ts index aa3b133f9..c8a70ecc3 100644 --- a/src/helpers/functions/errorHandler.ts +++ b/src/helpers/functions/errorHandler.ts @@ -123,7 +123,7 @@ export async function errorHandler(client: Client, error: any, type: string) { let eprotoError = false; let description = error.stack; - let codeBlocks = ""; + let codeBlocks = " "; if (error.isAxiosError) { // axios errors are JSON diff --git a/src/helpers/utility/handleJSON.ts b/src/helpers/utility/handleJSON.ts index 84b72b9c1..7c2973f2c 100644 --- a/src/helpers/utility/handleJSON.ts +++ b/src/helpers/utility/handleJSON.ts @@ -43,7 +43,7 @@ export function getData(options: GetOptions) { * @param options data to set */ export function setData(options: SetOptions) { - let folder = path.resolve(__dirname, options.relative_path); + const folder = path.resolve(__dirname, options.relative_path); const file = path.resolve(folder, options.filename); try {