Skip to content

Commit

Permalink
feat: restart command designed for pm2
Browse files Browse the repository at this point in the history
  • Loading branch information
kk committed Feb 26, 2023
1 parent fad50d7 commit 5c535f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/discord/RestartBot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ChatInputCommandInteraction, Client } from "discord.js";

const RestartBot = async (client: Client, interaction: ChatInputCommandInteraction): Promise<void> => {
if (interaction.commandName == "restart") {
// This type of restart is designed to be used with PM2.
process.exitCode = 0;
}
};

export default RestartBot;
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { getPlayerRank } from "@zikeji/hypixel";
import GuildXpCommand from "./discord/GuildXpCommand";
import { SeraphCache } from "./util/SeraphCache";
import GuildRequirements from "./discord/GuildRequirements";
import RestartBot from "./discord/RestartBot";

const config = require("../config.json5") as ConfigFile;

Expand Down Expand Up @@ -154,6 +155,7 @@ export class MinecraftBot {
return option;
}),
new SlashCommandBuilder().setName("guildxp").setDescription("Shows the guild's players based on requirements"),
new SlashCommandBuilder().setName("restart").setDescription("Restarts the bot"),
new SlashCommandBuilder()
.setName("reqcheck")
.addStringOption((command) => command.setName("name").setDescription("The name of the player you'd like to check.").setRequired(true))
Expand Down Expand Up @@ -334,6 +336,8 @@ export class MinecraftBot {
await GuildXpCommand(this.discord, interaction as ChatInputCommandInteraction);
} else if (interaction.commandName == "reqcheck" && perms.includes("reqcheck")) {
await GuildRequirements(this.discord, interaction as ChatInputCommandInteraction);
} else if (interaction.commandName == "restart" && perms.includes("restart")) {
await RestartBot(this.discord, interaction as ChatInputCommandInteraction);
} else {
await interaction.editReply(`You don't have the required permissions to execute this command! Missing: ${interaction.commandName}`);
}
Expand Down

0 comments on commit 5c535f1

Please sign in to comment.