Skip to content

Commit

Permalink
refactor: rename muted role
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-montaigut committed Sep 4, 2023
1 parent 10c037d commit c4fa467
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions src/modules/quoiFeur/quoiFeur.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { cache } from '../../core/cache';
import { removeEmoji, removePunctuation } from '../../helpers/regex.helper';

const ONE_MINUTE = 1 * 60 * 1000;
const MUTED_BY_BOT = 'Muted by bot';
const MUTED_ON_COUBEH = 'Muted on Coubeh';

const quoiDetectorRegex = /\bquoi\s*$/i;
const endWithQuoi = (text: string) => quoiDetectorRegex.test(removeEmoji(removePunctuation(text)));
Expand All @@ -32,7 +32,7 @@ const reactWithCoubeh = async (message: Message) => {
await message.react('🇭');
await message.react('🔇');

const mutedRole = message.guild?.roles.cache.find((r) => r.name === MUTED_BY_BOT);
const mutedRole = message.guild?.roles.cache.find((r) => r.name === MUTED_ON_COUBEH);

if (!mutedRole?.id) return;

Expand All @@ -59,24 +59,24 @@ export const reactOnEndWithQuoi = async (message: Message) => {
}
};

export const createRoleMutedByBot = async (guild: Guild | null): Promise<Role> => {
export const createRoleMutedOnCoubeh = async (guild: Guild | null): Promise<Role> => {
if (!guild) {
throw new Error('Guild is null in createRoleMutedByBot');
}
const existingMutedByBot = guild.roles.cache.find((role) => role.name === MUTED_BY_BOT);
const existingMutedByBot = guild.roles.cache.find((role) => role.name === MUTED_ON_COUBEH);

return (
existingMutedByBot ??
guild.roles.create({
name: MUTED_BY_BOT,
name: MUTED_ON_COUBEH,
})
);
};

export const deleteRoleMutedByBot = async (client: Client<true>): Promise<void> => {
export const deleteRoleMutedOnCoubeh = async (client: Client<true>): Promise<void> => {
const guilds = await client.guilds.fetch().then((guilds) => guilds.map((guild) => guild.fetch()));
const roles = await Promise.all(guilds).then((guilds) =>
guilds.map((guild) => guild.roles.cache.find((role) => role.name === MUTED_BY_BOT)),
guilds.map((guild) => guild.roles.cache.find((role) => role.name === MUTED_ON_COUBEH)),
);

for (const role of roles) {
Expand All @@ -95,7 +95,7 @@ export const addQuoiFeurToChannel = async (interaction: ChatInputCommandInteract
return;
}

const role = await createRoleMutedByBot(interaction.guild);
const role = await createRoleMutedOnCoubeh(interaction.guild);
await channel.permissionOverwrites.create(role, {
SendMessages: false,
CreatePublicThreads: false,
Expand All @@ -118,7 +118,7 @@ export const removeQuoiFeurFromChannel = async (interaction: ChatInputCommandInt
return;
}

const role = interaction.guild?.roles.cache.find((r) => r.name === MUTED_BY_BOT);
const role = interaction.guild?.roles.cache.find((r) => r.name === MUTED_ON_COUBEH);
if (role) {
await channel.permissionOverwrites.delete(role);
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/quoiFeur/quoiFeur.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SlashCommandBuilder } from 'discord.js';
import type { BotModule } from '../../types/bot';
import {
addQuoiFeurToChannel,
deleteRoleMutedByBot,
deleteRoleMutedOnCoubeh,
reactOnEndWithQuoi,
removeQuoiFeurFromChannel,
} from './quoiFeur.helpers';
Expand All @@ -29,7 +29,7 @@ export const quoiFeur: BotModule = {
],
eventHandlers: {
// unmute everyone in every server on bot restart
ready: deleteRoleMutedByBot,
ready: deleteRoleMutedOnCoubeh,
messageCreate: reactOnEndWithQuoi,
},
};

0 comments on commit c4fa467

Please sign in to comment.