Compare commits
2 commits
7c3eb13e28
...
403cefc737
Author | SHA1 | Date | |
---|---|---|---|
403cefc737 | |||
bba614198a |
2 changed files with 65 additions and 0 deletions
64
src/events/message/messageCreate.ts
Normal file
64
src/events/message/messageCreate.ts
Normal file
|
@ -0,0 +1,64 @@
|
|||
import { GuildBasedChannel, Message } from 'discord.js';
|
||||
|
||||
/** https://discord.js.org/#/docs/discord.js/main/class/Client?scrollTo=e-messageCreate */
|
||||
export default (message: Message) => {
|
||||
// Ignore message if
|
||||
if (
|
||||
// Author is a bot
|
||||
message.author.bot ||
|
||||
// Author is Discord
|
||||
message.author.system ||
|
||||
// Message isn't a message
|
||||
message.system ||
|
||||
// Message is in PM (future-proof if we add Intents.FLAGS.DIRECT_MESSAGES)
|
||||
!message.guild ||
|
||||
// Guild is offline
|
||||
!message.guild.available
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Citation */
|
||||
const regex = 'https://(?:canary\\.|ptb\\.)?discord(?:app)?\\.com/channels/(\\d{17,19})/(\\d{17,19})/(\\d{17,19})';
|
||||
const urls = message.content.match(new RegExp(regex, 'g'));
|
||||
|
||||
// Ignore message if there is no URLs
|
||||
if (!urls) {
|
||||
return;
|
||||
}
|
||||
|
||||
const messages = (
|
||||
urls.reduce(
|
||||
(data: {
|
||||
message_id: string;
|
||||
found_channel: GuildBasedChannel;
|
||||
}[] = [], match) => {
|
||||
const [,
|
||||
guild_id,
|
||||
channel_id,
|
||||
message_id,
|
||||
] = new RegExp(regex).exec(match) as RegExpExecArray;
|
||||
|
||||
// If message posted in another guild
|
||||
if (guild_id !== message.guild?.id) {
|
||||
return data;
|
||||
}
|
||||
|
||||
const found_channel =
|
||||
message.guild.channels.cache.get(channel_id);
|
||||
|
||||
// If channel doesn't exist in the guild
|
||||
if (!found_channel) {
|
||||
return data;
|
||||
}
|
||||
|
||||
data.push({ message_id, found_channel });
|
||||
|
||||
return data;
|
||||
},
|
||||
[]
|
||||
)
|
||||
);
|
||||
|
||||
console.log(messages);
|
||||
};
|
|
@ -45,6 +45,7 @@ export default async () => {
|
|||
const client: Client = new Client({
|
||||
intents: [
|
||||
Intents.FLAGS.GUILDS,
|
||||
Intents.FLAGS.GUILD_MESSAGES,
|
||||
],
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue