Skip to content

Commit 3288b14

Browse files
feat: add and remove game from channel
1 parent 6879106 commit 3288b14

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

src/commands.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,11 @@ export const fartCommand = new SlashCommandBuilder()
1515

1616
export const quoiFeurCommand = new SlashCommandBuilder()
1717
.setName('quoi-feur')
18-
.setDescription('Add quoi-feur game to the channel')
18+
.setDescription('Manage quoi-feur game in the channel')
19+
.addSubcommand((subcommand) =>
20+
subcommand.setName('add').setDescription('Add the quoi-feur game in the channel'),
21+
)
22+
.addSubcommand((subcommand) =>
23+
subcommand.setName('remove').setDescription('Remove the quoi-feur game in the channel'),
24+
)
1925
.toJSON();

src/handlers/handle-interaction-creation.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ export const handleInteractionCreation = async (interaction: Interaction): Promi
2525
await interaction.reply('https://prout.dev');
2626
break;
2727
case 'quoi-feur':
28-
await addQuoiFeurChannel(interaction);
28+
if (interaction.options.getSubcommand(true) === 'add') {
29+
await addQuoiFeurChannel(interaction);
30+
return;
31+
}
32+
if (interaction.options.getSubcommand(true) === 'remove') {
33+
await interaction.reply('Not implemented yet');
34+
return;
35+
}
36+
await interaction.reply('Unknown subcommand');
2937
break;
3038
}
3139
};

src/quoi-feur.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,25 @@ export const addQuoiFeurChannel = async (interaction: ChatInputCommandInteractio
7575
await cache.set('quoiFeurChannels', [...channels, channel.id]);
7676
await interaction.reply('Quoi-feur enabled in this channel');
7777
};
78+
79+
export const removeQuoiFeurChannel = async (interaction: ChatInputCommandInteraction) => {
80+
const channel = interaction.channel;
81+
if (!channel || !channel.isTextBased()) return;
82+
83+
const channels = await cache.get('quoiFeurChannels', []);
84+
if (!channels.includes(channel.id)) {
85+
await interaction.reply('Quoi-feur is not enabled in this channel');
86+
return;
87+
}
88+
89+
const role = interaction.guild?.roles.cache.find((r) => r.name === MUTED_BY_BOT);
90+
if (!role) return;
91+
if (!(channel instanceof TextChannel)) return;
92+
93+
await channel.permissionOverwrites.delete(role);
94+
await cache.set(
95+
'quoiFeurChannels',
96+
channels.filter((channelId) => channelId !== channel.id),
97+
);
98+
await interaction.reply('Quoi-feur disabled in this channel');
99+
};

0 commit comments

Comments
 (0)