Skip to content

Commit 7ace5b6

Browse files
author
AbdelMN
committed
add quoi-feur feature in threads
1 parent ba3a50d commit 7ace5b6

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

.env.example

Lines changed: 0 additions & 11 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"typescript": "5.3.3",
4545
"vitest": "1.2.1"
4646
},
47-
"packageManager": "pnpm@8.14.1",
47+
"packageManager": "pnpm@8.15.1+sha256.245fe901f8e7fa8782d7f17d32b6a83995e2ae03984cb5b62b8949bfdc27c7b5",
4848
"engines": {
4949
"node": "21.6.0"
5050
}

src/modules/quoiFeur/quoiFeur.helpers.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import {
2+
PermissionFlagsBits,
23
ChannelType,
34
type ChatInputCommandInteraction,
45
DMChannel,
6+
type Channel,
7+
type User,
58
type Message,
69
type NonThreadGuildBasedChannel,
710
} from 'discord.js';
@@ -62,10 +65,23 @@ export const reactOnEndWithQuoi = async (message: Message) => {
6265
await reactWithFeur(message);
6366
};
6467

65-
export const addQuoiFeurToChannel = async (interaction: ChatInputCommandInteraction) => {
66-
const { channel } = interaction;
67-
if (!channel || !channel.isTextBased() || channel.type !== ChannelType.GuildText) return;
68+
const isOwner = (channel : Channel, user : User) => {
69+
if(channel.type == ChannelType.PublicThread){
70+
if(user.id == channel.ownerId) return true;
71+
}
72+
console.log("lol");
73+
return;
74+
}
6875

76+
export const addQuoiFeurToChannel = async (interaction: ChatInputCommandInteraction) => {
77+
const { channel, memberPermissions, user } = interaction;
78+
79+
if (!memberPermissions || !channel || !channel.isTextBased() || (channel.type !== ChannelType.GuildText && channel.type !== ChannelType.PublicThread)) return;
80+
if (!memberPermissions.has(PermissionFlagsBits.ManageChannels) && !isOwner(channel, user) ){
81+
await interaction.reply({ content: 'You don\'t have permissions to enable Quoi-feur in this channel', ephemeral: true });
82+
return;
83+
}
84+
6985
const channels = await cache.get('quoiFeurChannels', []);
7086
if (channels.includes(channel.id)) {
7187
await interaction.reply({
@@ -80,9 +96,14 @@ export const addQuoiFeurToChannel = async (interaction: ChatInputCommandInteract
8096
};
8197

8298
export const removeQuoiFeurFromChannel = async (interaction: ChatInputCommandInteraction) => {
83-
const { channel } = interaction;
84-
if (!channel || !channel.isTextBased() || channel.type !== ChannelType.GuildText) return;
99+
const { channel, memberPermissions, user } = interaction;
85100

101+
if (!memberPermissions || !channel || !channel.isTextBased() || (channel.type !== ChannelType.GuildText && channel.type !== ChannelType.PublicThread)) return;
102+
if (!memberPermissions.has(PermissionFlagsBits.ManageChannels) && !isOwner(channel, user) ){
103+
await interaction.reply({ content: 'You don\'t have permissions to disable Quoi-feur in this channel', ephemeral: true });
104+
return;
105+
}
106+
86107
const channels = await cache.get('quoiFeurChannels', []);
87108
if (!channels.includes(channel.id)) {
88109
await interaction.reply({

src/modules/quoiFeur/quoiFeur.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
1+
import { SlashCommandBuilder } from 'discord.js';
22

33
import { createModule } from '../../core/createModule';
44
import {
@@ -21,7 +21,7 @@ export const quoiFeur = createModule({
2121
.addSubcommand((subcommand) =>
2222
subcommand.setName('disable').setDescription('Disable the quoi-feur game in the channel'),
2323
)
24-
.setDefaultMemberPermissions(PermissionFlagsBits.ManageChannels)
24+
2525
.toJSON(),
2626
handler: {
2727
enable: addQuoiFeurToChannel,

0 commit comments

Comments
 (0)