Skip to content

Commit

Permalink
feat(notifs): now notify network channel when a in-use webhook is del…
Browse files Browse the repository at this point in the history
…eted
  • Loading branch information
dev-737 committed Apr 21, 2024
1 parent 9187cd1 commit 75ad29e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
20 changes: 19 additions & 1 deletion src/InterChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { check } from './utils/Profanity.js';
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from 'discord.js';
import { stripIndents } from 'common-tags';
import { LINKS, channels, colors, emojis } from './utils/Constants.js';
import { loadLocales } from './utils/Locale.js';
import { loadLocales, t } from './utils/Locale.js';
import { logGuildJoin, logGuildLeave } from './scripts/guilds/goals.js';
import getWelcomeTargets from './scripts/guilds/getWelcomeTarget.js';

Expand Down Expand Up @@ -122,6 +122,24 @@ class InterChat extends SuperClient {
await logGuildLeave(guild, channels.goal);
});

this.on('webhookUpdate', async (channel) => {
const isNetworkChannel = await db.connectedList.findFirst({
where: { OR: [{ channelId: channel.id }, { parentId: channel.id }], connected: true },
});
if (!isNetworkChannel) return;

const webhooks = await channel.fetchWebhooks();
const webhook = webhooks.find((w) => w.url === isNetworkChannel.webhookURL);
if (!webhook) {
const channelToSend = await this.channels.fetch(isNetworkChannel.channelId);
if (channelToSend?.isTextBased()) {
channelToSend.send(
t({ phrase: 'webhookNoLongerExists', locale: 'en' }, { emoji: emojis.info }),
);
}
}
});

this.on('messageCreate', (message) => this.networkManager.onMessageCreate(message));

this.on('interactionCreate', (interaction) =>
Expand Down
7 changes: 6 additions & 1 deletion src/commands/context-menu/editMsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ export default class EditMessage extends BaseCommand {
const hubSettings = new HubSettingsBitField(messageInDb.originalMsg.hub.settings);
const newMessage = hubSettings.has('HideLinks') ? replaceLinks(userInput) : userInput;
const { newEmbed, censoredEmbed, compactMsg, censoredCmpctMsg } =
await EditMessage.fabricateNewMsg(interaction.user, target, newMessage, messageInDb.originalMsg.serverId);
await EditMessage.fabricateNewMsg(
interaction.user,
target,
newMessage,
messageInDb.originalMsg.serverId,
);

if (
hubSettings.has('BlockInvites') &&
Expand Down
10 changes: 3 additions & 7 deletions src/utils/Profanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ export function check(string: string | undefined) {

return {
profanity: profanity.some((word) =>
string
.split(/\b/)
.some((w) => w.toLowerCase() === word.toLowerCase()),
string.split(/\b/).some((w) => w.toLowerCase() === word.toLowerCase()),
),
slurs: slurs.some((word) =>
string
.split(/\b/)
.some((w) => w.toLowerCase() === word.toLowerCase()),
)
string.split(/\b/).some((w) => w.toLowerCase() === word.toLowerCase()),
),
};
}

Expand Down

0 comments on commit 75ad29e

Please sign in to comment.