Skip to content

Commit 72561d5

Browse files
committed
added master commands
1 parent 87ef06e commit 72561d5

5 files changed

Lines changed: 21 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ GUILD_ID=
130130
131131
GREET_CHANNEL_ID=
132132
LOG_CHANNEL_ID=
133+
MASTER_GUILD=
133134
134135
DATABASE_URL=postgresql://user:password@localhost:5432/boostify
135136
```

src/base/classes/command.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface CommandOptions {
2121
ownerOnly?: boolean;
2222
requiredPermissions?: (keyof typeof PermissionFlagsBits)[];
2323
cooldown?: number;
24+
masterLock?: boolean
2425
}
2526

2627
export class Command {
@@ -30,15 +31,17 @@ export class Command {
3031
ownerOnly: boolean;
3132
requiredPermissions: (keyof typeof PermissionFlagsBits)[];
3233
cooldown: number;
34+
masterLock: boolean
3335
private _cooldowns: Map<string, number>;
3436

35-
constructor({ info, execute, guildOnly = false, ownerOnly = false, requiredPermissions = [], cooldown = 0 }: CommandOptions) {
37+
constructor({ info, execute, guildOnly = false, ownerOnly = false, requiredPermissions = [], cooldown = 0, masterLock = false }: CommandOptions) {
3638
this.data = info;
3739
this.execute = execute;
3840
this.guildOnly = guildOnly;
3941
this.ownerOnly = ownerOnly;
4042
this.requiredPermissions = requiredPermissions;
4143
this.cooldown = cooldown;
44+
this.masterLock = masterLock;
4245
this._cooldowns = new Map();
4346
}
4447

@@ -57,6 +60,12 @@ export class Command {
5760
return;
5861
}
5962

63+
if (this.masterLock && interaction.guild) {
64+
if (interaction.guild.id != process.env.MASTER_GUILD) {
65+
await interaction.reply('This command cannot be ran in this server.')
66+
}
67+
}
68+
6069
if (this.requiredPermissions.length && interaction.guild) {
6170
const missing = this.requiredPermissions.filter(
6271
p => !interaction.memberPermissions?.has(PermissionFlagsBits[p])

src/commands/reload.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
} from "discord.js";
66
import { loadCommands } from "../libs/loadCommands.js";
77
import { Command } from "../base/classes/command.js";
8-
import { client } from "../index.js";
98

109
export default new Command({
1110
info: new SlashCommandBuilder()
@@ -23,5 +22,6 @@ export default new Command({
2322
await interaction.editReply("Failed to reload commands.");
2423
}
2524
},
26-
requiredPermissions: ["Administrator"]
25+
requiredPermissions: ["Administrator"],
26+
masterLock: true
2727
})

src/libs/loadCommands.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ export async function loadCommands(): Promise<void> {
5454
continue;
5555
}
5656

57+
if (command?.masterLock) {
58+
if (!process.env.MASTER_GUILD) {
59+
logger.warn(`Skipping ${file} - missing ${chalk.bold('MASTER_GUILD')} on environmental variables.`);
60+
continue;
61+
}
62+
}
63+
5764
client.commands.set(command.data.name, command);
5865
commandData.push(command.data.toJSON());
5966
}

src/libs/loadVariables.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const envSchema = z.object({
88
GREET_CHANNEL_ID: z.string().min(1).optional(),
99
LOG_CHANNEL_ID: z.string().min(1).optional(),
1010
DATABASE_URL: z.string().min(1),
11+
MASTER_GUILD: z.string().optional()
1112
});
1213

1314
declare global {

0 commit comments

Comments
 (0)