Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/handlers/handle-guild-message-creation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { Message } from 'discord.js';
import { MessageType } from 'discord.js';

export const handleGuildMessageCreation = async (message: Message) => {
if (message.author.bot) {
return;
}

if (message.type !== MessageType.Default) {
return;
}

const urls = message.content.match(/https?:\/\/\S+/g);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi, can you please make a check if there is some twitter links in the message ? Because the bot will send a message on every message.

if (urls === null) {
return;
}

const newContent = message.content.replaceAll(
/https?:\/\/(mobile\.)?twitter\.com/g,
'https://vxtwitter.com'
);

const newMessage = [`<@${message.author.id}>`, newContent].join('\n');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it's clear enough for the users to only mention the name of the user. It can be better to put Message de : @Ayoub or something else 🤷‍♂️


await message.channel.send(newMessage);
await message.delete();
};
7 changes: 6 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Client, REST, Routes } from 'discord.js';
import { voiceOnDemandCommand } from './commands';
import { config } from './config';
import { deleteExistingCommands } from './delete-existing-commands';
import { handleGuildMessageCreation } from './handlers/handle-guild-message-creation';
import { handleInteractionCreation } from './handlers/handle-interaction-creation';
import { handleVoiceChannelDeletion } from './handlers/handle-voice-channel-deletion';
import { handleVoiceStateUpdate } from './handlers/handle-voice-state-update';
Expand All @@ -24,7 +25,7 @@ const bootstrap = async (client: Client) => {
};

const client = new Client({
intents: ['Guilds', 'GuildVoiceStates', 'GuildMembers'],
intents: ['Guilds', 'GuildVoiceStates', 'GuildMembers', 'GuildMessages', 'MessageContent'],
});

await bootstrap(client);
Expand All @@ -41,6 +42,10 @@ client.on('interactionCreate', async (interaction) => {
await handleInteractionCreation(interaction);
});

client.on('messageCreate', async (message) => {
await handleGuildMessageCreation(message);
});

const rest = new REST({ version: '10' }).setToken(discord.token);

await deleteExistingCommands(rest, discord);
Expand Down