Skip to content

Commit

Permalink
feat: Add admin check on running the commands
Browse files Browse the repository at this point in the history
  • Loading branch information
KikyoNanakusa committed Oct 2, 2024
1 parent 96f668d commit c3f3f41
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/commands/kill.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type CommandInteraction, SlashCommandBuilder } from "discord.js";
import type CommandWithArgs from "../types/commandWithArgs";
import checkIsAdmin from "../utils/checkMemberRole";

const killCommand: CommandWithArgs = {
data: new SlashCommandBuilder()
Expand All @@ -15,6 +16,11 @@ const killCommand: CommandWithArgs = {
};

async function killCommandHandler(interaction: CommandInteraction) {
//adminロールを持っているか確認
const isAdmin: boolean = await checkIsAdmin(interaction);
if (!isAdmin)
return await interaction.reply("このコマンドは管理者のみ使用可能です。");

const targetPid = interaction.options.get("pid")?.value as string;
const currentPid = process.pid.toString();

Expand Down
6 changes: 6 additions & 0 deletions src/commands/ps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as os from "node:os";
import { type CommandInteraction, SlashCommandBuilder } from "discord.js";
import type CommandWithArgs from "../types/commandWithArgs";
import checkIsAdmin from "../utils/checkMemberRole";

const psCommand: CommandWithArgs = {
data: new SlashCommandBuilder()
Expand All @@ -10,6 +11,11 @@ const psCommand: CommandWithArgs = {
};

async function psCommandHandler(interaction: CommandInteraction) {
//adminロールを持っているか確認
const isAdmin: boolean = await checkIsAdmin(interaction);
if (!isAdmin)
return await interaction.reply("このコマンドは管理者のみ使用可能です。");

const processInfo = await getProcessInfo();
await interaction.reply(
`ボットプロセス情報:\nPID: ${processInfo.pid}\nホスト名: ${processInfo.hostname}`,
Expand Down

0 comments on commit c3f3f41

Please sign in to comment.