Skip to content

Commit 92d14d9

Browse files
fix: pr returns adjustement
1 parent d9cb95a commit 92d14d9

File tree

3 files changed

+18
-26
lines changed

3 files changed

+18
-26
lines changed

src/helpers/regex.helper.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ const socialNetworksUrlRegex = new RegExp(
33
);
44
const punctuationRegex = new RegExp(/[.,!?]/g);
55
const emojiRegex = new RegExp(/(\p{Extended_Pictographic}|\p{Emoji_Component})/gu);
6-
const quoiDetectorRegex = new RegExp(/\b\s*[q][u][o][i]\s*$/i);
76

87
export const isASocialNetworkUrl = (url: string): boolean => {
98
return socialNetworksUrlRegex.test(url);
109
};
1110

1211
export const removePunctuation = (text: string) => text.replaceAll(punctuationRegex, '');
1312
export const removeEmoji = (text: string) => text.replaceAll(emojiRegex, '');
14-
export const endWithQuoi = (text: string) =>
15-
quoiDetectorRegex.test(removeEmoji(removePunctuation(text)));

src/modules/quoiFeur/quoiFeur.helpers.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import {
22
ChannelType,
33
type ChatInputCommandInteraction,
4+
Client,
45
Guild,
56
type Message,
67
Role,
78
} from 'discord.js';
89

910
import { cache } from '../../core/cache';
10-
import { endWithQuoi } from '../../helpers/regex.helper';
11+
import { removeEmoji, removePunctuation } from '../../helpers/regex.helper';
1112

1213
const ONE_MINUTE = 1 * 60 * 1000;
1314
const MUTED_BY_BOT = 'Muted by bot';
1415

16+
const quoiDetectorRegex = new RegExp(/\b\s*[q][u][o][i]\s*$/i);
17+
const endWithQuoi = (text: string) => quoiDetectorRegex.test(removeEmoji(removePunctuation(text)));
18+
1519
const reactWithFeur = async (message: Message) => {
1620
await message.react('🇫');
1721
await message.react('🇪');
@@ -69,14 +73,15 @@ export const createRoleMutedByBot = async (guild: Guild | null): Promise<Role> =
6973
);
7074
};
7175

72-
export const deleteRoleMutedByBot = async (guild: Guild | null): Promise<void> => {
73-
if (!guild) {
74-
throw new Error('Guild is null in removeRoleMutedByBot');
75-
}
76-
const existingMutedByBot = guild.roles.cache.find((role) => role.name === MUTED_BY_BOT);
76+
export const deleteRoleMutedByBot = async (client: Client<true>): Promise<void> => {
77+
const guilds = await client.guilds.fetch().then((guilds) => guilds.map((guild) => guild.fetch()));
78+
const roles = await Promise.all(guilds).then((guilds) =>
79+
guilds.map((guild) => guild.roles.cache.find((role) => role.name === MUTED_BY_BOT)),
80+
);
7781

78-
if (existingMutedByBot) {
79-
await existingMutedByBot.delete();
82+
for (const role of roles) {
83+
if (!role) continue;
84+
await role.delete();
8085
}
8186
};
8287

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { SlashCommandBuilder } from 'discord.js';
22

3-
import { config } from '../../config';
43
import type { BotModule } from '../../types/bot';
54
import {
65
addQuoiFeurToChannel,
@@ -23,23 +22,14 @@ export const quoiFeur: BotModule = {
2322
)
2423
.toJSON(),
2524
handler: {
26-
add: async (interaction) => {
27-
await addQuoiFeurToChannel(interaction).catch(console.error);
28-
},
29-
remove: async (interaction) => {
30-
await removeQuoiFeurFromChannel(interaction).catch(console.error);
31-
},
25+
add: addQuoiFeurToChannel,
26+
remove: removeQuoiFeurFromChannel,
3227
},
3328
},
3429
],
3530
eventHandlers: {
36-
ready: async (client) => {
37-
const guild = client.guilds.cache.get(config.discord.guildId) ?? null;
38-
// unmute everyone on bot restart
39-
await deleteRoleMutedByBot(guild).catch(console.error);
40-
},
41-
messageCreate: async (message) => {
42-
await reactOnEndWithQuoi(message).catch(console.error);
43-
},
31+
// unmute everyone in every server on bot restart
32+
ready: deleteRoleMutedByBot,
33+
messageCreate: reactOnEndWithQuoi,
4434
},
4535
};

0 commit comments

Comments
 (0)