Skip to content

Commit 6448e24

Browse files
feat: add permissions on command /cron
1 parent 4edb171 commit 6448e24

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/add-cron.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ import { CronJob } from 'cron';
22
import { ChatInputCommandInteraction } from 'discord.js';
33

44
import { getCronTime } from './helpers/get-cron-time';
5+
import { isModo } from './helpers/roles';
56

6-
export const addCron = (interaction: ChatInputCommandInteraction): void => {
7+
export const addCron = async (interaction: ChatInputCommandInteraction): Promise<void> => {
8+
if (!isModo(interaction.member)) {
9+
await interaction.reply('You are not allowed to use this command');
10+
return;
11+
}
712
const frequency = interaction.options.getString('every', true);
813
const message = interaction.options.getString('message', true);
914

@@ -17,4 +22,6 @@ export const addCron = (interaction: ChatInputCommandInteraction): void => {
1722
'Europe/Paris',
1823
);
1924
job.start();
25+
26+
await interaction.reply(`Recurring message added every ${frequency}`);
2027
};

src/handlers/handle-interaction-creation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const handleInteractionCreation = async (interaction: Interaction): Promi
2929
await interaction.reply('Unknown subcommand');
3030
return;
3131
}
32-
addCron(interaction);
32+
await addCron(interaction);
3333
break;
3434
}
3535
};

src/helpers/roles.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { type APIInteractionGuildMember, GuildMember } from 'discord.js';
2+
3+
export const isAdmin = (member: GuildMember | APIInteractionGuildMember | null): boolean =>
4+
member instanceof GuildMember && member.roles.cache.some((role) => role.name === 'Admin');
5+
6+
export const isModo = (member: GuildMember | APIInteractionGuildMember | null): boolean =>
7+
member instanceof GuildMember &&
8+
member.roles.cache.some((role) => role.name === 'Admin' || role.name === 'Modo');

0 commit comments

Comments
 (0)