PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 1 | import type { NucleusClient } from "../utils/client.js"; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 2 | import { LinkCheck, MalwareCheck, NSFWCheck, SizeCheck, TestString, TestImage } from "../reflex/scanners.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 3 | import logAttachment from "../premium/attachmentLogs.js"; |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 4 | import { messageException } from "../utils/createTemporaryStorage.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 5 | import getEmojiByName from "../utils/getEmojiByName.js"; |
| 6 | import client from "../utils/client.js"; |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 7 | import { callback as statsChannelUpdate } from "../reflex/statsChannelUpdate.js"; |
TheCodedProf | c7e8ef1 | 2023-04-22 22:28:11 -0400 | [diff] [blame] | 8 | import { ChannelType, GuildMember, Message, ThreadChannel } from "discord.js"; |
TheCodedProf | b7a7b99 | 2023-03-05 16:11:59 -0500 | [diff] [blame] | 9 | import singleNotify from "../utils/singleNotify.js"; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 10 | |
TheCodedProf | 680c497 | 2023-04-23 15:14:08 -0400 | [diff] [blame] | 11 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 12 | export const event = "messageCreate"; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 13 | |
TheCodedProf | c7e8ef1 | 2023-04-22 22:28:11 -0400 | [diff] [blame] | 14 | function checkUserForExceptions(user: GuildMember, exceptions: { roles: string[]; users: string[] }) { |
| 15 | if (exceptions.users.includes(user.id)) return true; |
| 16 | for (const role of user.roles.cache.values()) { |
| 17 | if (exceptions.roles.includes(role.id)) return true; |
| 18 | } |
| 19 | return false; |
| 20 | } |
| 21 | |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 22 | export async function callback(_client: NucleusClient, message: Message) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 23 | if (!message.guild) return; |
PineappleFan | 13892c6 | 2023-03-05 07:00:07 +0000 | [diff] [blame] | 24 | const config = await client.memory.readGuildInfo(message.guild.id); |
Skyler | 9f5fca8 | 2023-03-05 09:12:03 +0000 | [diff] [blame] | 25 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 26 | if ( |
| 27 | config.autoPublish.enabled && |
| 28 | config.autoPublish.channels.includes(message.channel.id) && |
| 29 | message.channel.type === ChannelType.GuildAnnouncement && |
| 30 | message.reference === null |
Skyler | 9f5fca8 | 2023-03-05 09:12:03 +0000 | [diff] [blame] | 31 | ) { |
Skyler Grey | 6769176 | 2023-03-06 09:58:19 +0000 | [diff] [blame] | 32 | if (message.channel.permissionsFor(message.guild.members.me!)!.has("ManageMessages")) { |
TheCodedProf | b7a7b99 | 2023-03-05 16:11:59 -0500 | [diff] [blame] | 33 | await message.crosspost(); |
| 34 | } else { |
Skyler Grey | f4f21c4 | 2023-03-08 14:36:29 +0000 | [diff] [blame] | 35 | await singleNotify( |
| 36 | `Nucleus does not have Manage Messages in <#${message.channel.id}>`, |
| 37 | message.guild.id, |
| 38 | true |
| 39 | ); |
TheCodedProf | b7a7b99 | 2023-03-05 16:11:59 -0500 | [diff] [blame] | 40 | } |
PineappleFan | 13892c6 | 2023-03-05 07:00:07 +0000 | [diff] [blame] | 41 | } |
| 42 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 43 | if (message.author.bot) return; |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 44 | if (message.channel.isDMBased()) return; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 45 | try { |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 46 | await statsChannelUpdate((await message.guild.members.fetch(message.author.id)).user, message.guild); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 47 | } catch (e) { |
| 48 | console.log(e); |
| 49 | } |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 50 | |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 51 | const { log, isLogging, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 52 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 53 | const fileNames = await logAttachment(message); |
TheCodedProf | 22586d5 | 2023-04-23 16:46:32 -0400 | [diff] [blame] | 54 | const lowerCaseContent = message.content.toLowerCase() || ""; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 55 | if (config.filters.clean.channels.includes(message.channel.id)) { |
TheCodedProf | c7e8ef1 | 2023-04-22 22:28:11 -0400 | [diff] [blame] | 56 | if (!checkUserForExceptions(message.member!, config.filters.clean.allowed)) return await message.delete(); |
TheCodedProf | ad0b820 | 2023-02-14 14:27:09 -0500 | [diff] [blame] | 57 | } |
TheCodedProf | baee2c1 | 2023-02-18 16:11:06 -0500 | [diff] [blame] | 58 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 59 | const filter = getEmojiByName("ICONS.FILTER"); |
| 60 | let attachmentJump = ""; |
TheCodedProf | 680c497 | 2023-04-23 15:14:08 -0400 | [diff] [blame] | 61 | console.log(config.logging.attachments.saved) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 62 | if (config.logging.attachments.saved[message.channel.id + message.id]) { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 63 | attachmentJump = ` [[View attachments]](${config.logging.attachments.saved[message.channel.id + message.id]})`; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 64 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 65 | const list = { |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 66 | messageId: entry(message.id, `\`${message.id}\``), |
| 67 | sentBy: entry(message.author.id, renderUser(message.author)), |
| 68 | sentIn: entry(message.channel.id, renderChannel(message.channel)), |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 69 | deleted: entry(Date.now(), renderDelta(Date.now())), |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 70 | mentions: message.mentions.users.size, |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 71 | attachments: entry(message.attachments.size, message.attachments.size + attachmentJump), |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 72 | repliedTo: entry( |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 73 | (message.reference ? message.reference.messageId : null) ?? null, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 74 | message.reference |
| 75 | ? `[[Jump to message]](https://discord.com/channels/${message.guild.id}/${message.channel.id}/${message.reference.messageId})` |
| 76 | : "None" |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 77 | ) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 78 | }; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 79 | |
| 80 | if (config.filters.invite.enabled) { |
TheCodedProf | c7e8ef1 | 2023-04-22 22:28:11 -0400 | [diff] [blame] | 81 | if ( |
| 82 | !config.filters.invite.allowed.channels.includes(message.channel.id) || |
| 83 | !checkUserForExceptions(message.member!, config.filters.invite.allowed) |
| 84 | ) { |
TheCodedProf | 22586d5 | 2023-04-23 16:46:32 -0400 | [diff] [blame] | 85 | if (/(?:https?:\/\/)?discord(?:app)?\.(?:com\/invite|gg)\/[a-zA-Z0-9]+\/?/.test(lowerCaseContent)) { |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 86 | messageException(message.guild.id, message.channel.id, message.id); |
Skyler Grey | f4f21c4 | 2023-03-08 14:36:29 +0000 | [diff] [blame] | 87 | await message.delete(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 88 | const data = { |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 89 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 90 | type: "messageDelete", |
pineafan | fa44599 | 2023-03-06 16:21:51 +0000 | [diff] [blame] | 91 | displayName: "Message Deleted", |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 92 | calculateType: "autoModeratorDeleted", |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 93 | color: NucleusColors.red, |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 94 | emoji: "MESSAGE.DELETE", |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 95 | timestamp: Date.now() |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 96 | }, |
| 97 | separate: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 98 | start: |
| 99 | filter + |
| 100 | " Contained invite\n\n" + |
TheCodedProf | 22586d5 | 2023-04-23 16:46:32 -0400 | [diff] [blame] | 101 | (lowerCaseContent ? `**Message:**\n\`\`\`${message.content}\`\`\`` : "**Message:** *Message had no content*") |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 102 | }, |
| 103 | list: list, |
| 104 | hidden: { |
| 105 | guild: message.channel.guild.id |
| 106 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 107 | }; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 108 | return log(data); |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | if (fileNames.files.length > 0) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 114 | for (const element of fileNames.files) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 115 | const url = element.url ? element.url : element.local; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 116 | if ( |
Skyler Grey | 0d88522 | 2023-03-08 21:46:37 +0000 | [diff] [blame] | 117 | /\.(jpg|jpeg|png|apng|gif|gifv|webm|webp|mp4|wav|mp3|ogg|jfif|mpeg-\d|avi|h\.264|h\.265)$/.test( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 118 | url.toLowerCase() |
| 119 | ) |
| 120 | ) { |
Skyler Grey | 0d88522 | 2023-03-08 21:46:37 +0000 | [diff] [blame] | 121 | // j(pe?g|fif)|a?png|gifv?|w(eb[mp]|av)|mp([34]|eg-\d)|ogg|avi|h\.26(4|5) |
| 122 | // ^no |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 123 | if ( |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 124 | config.filters.images.NSFW && |
Skyler Grey | 0d88522 | 2023-03-08 21:46:37 +0000 | [diff] [blame] | 125 | !(message.channel instanceof ThreadChannel ? message.channel.parent?.nsfw : message.channel.nsfw) && |
Skyler Grey | 7416964 | 2023-03-09 11:59:09 +0000 | [diff] [blame] | 126 | (await NSFWCheck(element.url)) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 127 | ) { |
Skyler Grey | 0d88522 | 2023-03-08 21:46:37 +0000 | [diff] [blame] | 128 | messageException(message.guild.id, message.channel.id, message.id); |
| 129 | await message.delete(); |
| 130 | const data = { |
| 131 | meta: { |
| 132 | type: "messageDelete", |
| 133 | displayName: "Message Deleted", |
| 134 | calculateType: "autoModeratorDeleted", |
| 135 | color: NucleusColors.red, |
| 136 | emoji: "MESSAGE.DELETE", |
| 137 | timestamp: Date.now() |
| 138 | }, |
| 139 | separate: { |
| 140 | start: |
| 141 | filter + |
| 142 | " Image detected as NSFW\n\n" + |
TheCodedProf | 22586d5 | 2023-04-23 16:46:32 -0400 | [diff] [blame] | 143 | (lowerCaseContent |
| 144 | ? `**Message:**\n\`\`\`${message.content}\`\`\`` |
Skyler Grey | 0d88522 | 2023-03-08 21:46:37 +0000 | [diff] [blame] | 145 | : "**Message:** *Message had no content*") |
| 146 | }, |
| 147 | list: list, |
| 148 | hidden: { |
| 149 | guild: message.channel.guild.id |
| 150 | } |
| 151 | }; |
| 152 | return log(data); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 153 | } |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 154 | if (config.filters.wordFilter.enabled) { |
| 155 | const text = await TestImage(url); |
| 156 | const check = TestString( |
| 157 | text ?? "", |
| 158 | config.filters.wordFilter.words.loose, |
| 159 | config.filters.wordFilter.words.strict |
| 160 | ); |
TheCodedProf | c7e8ef1 | 2023-04-22 22:28:11 -0400 | [diff] [blame] | 161 | if ( |
| 162 | check !== null && |
| 163 | (!checkUserForExceptions(message.member!, config.filters.wordFilter.allowed) || |
| 164 | !config.filters.wordFilter.allowed.channels.includes(message.channel.id)) |
| 165 | ) { |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 166 | messageException(message.guild.id, message.channel.id, message.id); |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 167 | await message.delete(); |
| 168 | const data = { |
| 169 | meta: { |
| 170 | type: "messageDelete", |
| 171 | displayName: "Message Deleted", |
| 172 | calculateType: "autoModeratorDeleted", |
| 173 | color: NucleusColors.red, |
| 174 | emoji: "MESSAGE.DELETE", |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 175 | timestamp: Date.now() |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 176 | }, |
| 177 | separate: { |
| 178 | start: |
| 179 | filter + |
| 180 | " Image contained filtered word\n\n" + |
TheCodedProf | 22586d5 | 2023-04-23 16:46:32 -0400 | [diff] [blame] | 181 | (lowerCaseContent |
| 182 | ? `**Message:**\n\`\`\`${message.content}\`\`\`` |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 183 | : "**Message:** *Message had no content*") |
| 184 | }, |
| 185 | list: list, |
| 186 | hidden: { |
| 187 | guild: message.channel.guild.id |
| 188 | } |
| 189 | }; |
| 190 | return log(data); |
| 191 | } |
| 192 | } |
| 193 | if (config.filters.images.size) { |
| 194 | if (url.match(/\.+(webp|png|jpg)$/gi)) { |
| 195 | if (!(await SizeCheck(element))) { |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 196 | messageException(message.guild.id, message.channel.id, message.id); |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 197 | await message.delete(); |
| 198 | const data = { |
| 199 | meta: { |
| 200 | type: "messageDelete", |
| 201 | displayName: "Message Deleted", |
| 202 | calculateType: "autoModeratorDeleted", |
| 203 | color: NucleusColors.red, |
| 204 | emoji: "MESSAGE.DELETE", |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 205 | timestamp: Date.now() |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 206 | }, |
| 207 | separate: { |
| 208 | start: |
| 209 | filter + |
| 210 | " Image was too small\n\n" + |
TheCodedProf | 22586d5 | 2023-04-23 16:46:32 -0400 | [diff] [blame] | 211 | (lowerCaseContent |
| 212 | ? `**Message:**\n\`\`\`${message.content}\`\`\`` |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame] | 213 | : "**Message:** *Message had no content*") |
| 214 | }, |
| 215 | list: list, |
| 216 | hidden: { |
| 217 | guild: message.channel.guild.id |
| 218 | } |
| 219 | }; |
| 220 | return log(data); |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | } |
Skyler Grey | 0d88522 | 2023-03-08 21:46:37 +0000 | [diff] [blame] | 225 | if (config.filters.malware && (await MalwareCheck(url))) { |
| 226 | messageException(message.guild.id, message.channel.id, message.id); |
| 227 | await message.delete(); |
| 228 | const data = { |
| 229 | meta: { |
| 230 | type: "messageDelete", |
| 231 | displayName: "Message Deleted", |
| 232 | calculateType: "autoModeratorDeleted", |
| 233 | color: NucleusColors.red, |
| 234 | emoji: "MESSAGE.DELETE", |
| 235 | timestamp: Date.now() |
| 236 | }, |
| 237 | separate: { |
| 238 | start: |
| 239 | filter + |
| 240 | " File detected as malware\n\n" + |
TheCodedProf | 22586d5 | 2023-04-23 16:46:32 -0400 | [diff] [blame] | 241 | (lowerCaseContent ? `**Message:**\n\`\`\`${message.content}\`\`\`` : "**Message:** *Message had no content*") |
Skyler Grey | 0d88522 | 2023-03-08 21:46:37 +0000 | [diff] [blame] | 242 | }, |
| 243 | list: list, |
| 244 | hidden: { |
| 245 | guild: message.channel.guild.id |
| 246 | } |
| 247 | }; |
| 248 | return log(data); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 249 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 250 | } |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 251 | } |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 252 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 253 | const linkDetectionTypes = await LinkCheck(message); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 254 | if (linkDetectionTypes.length > 0) { |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 255 | messageException(message.guild.id, message.channel.id, message.id); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 256 | await message.delete(); |
| 257 | const data = { |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 258 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 259 | type: "messageDelete", |
| 260 | displayName: "Message Deleted", |
| 261 | calculateType: "autoModeratorDeleted", |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 262 | color: NucleusColors.red, |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 263 | emoji: "MESSAGE.DELETE", |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 264 | timestamp: Date.now() |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 265 | }, |
| 266 | separate: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 267 | start: |
| 268 | filter + |
| 269 | ` Link filtered as ${linkDetectionTypes[0]?.toLowerCase()}\n\n` + |
TheCodedProf | 22586d5 | 2023-04-23 16:46:32 -0400 | [diff] [blame] | 270 | (lowerCaseContent ? `**Message:**\n\`\`\`${message.content}\`\`\`` : "**Message:** *Message had no content*") |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 271 | }, |
| 272 | list: list, |
| 273 | hidden: { |
| 274 | guild: message.channel.guild.id |
| 275 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 276 | }; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 277 | return log(data); |
| 278 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 279 | |
TheCodedProf | c7e8ef1 | 2023-04-22 22:28:11 -0400 | [diff] [blame] | 280 | if ( |
| 281 | config.filters.wordFilter.enabled && |
| 282 | (!checkUserForExceptions(message.member!, config.filters.wordFilter.allowed) || |
| 283 | !config.filters.wordFilter.allowed.channels.includes(message.channel.id)) |
| 284 | ) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 285 | const check = TestString( |
TheCodedProf | 22586d5 | 2023-04-23 16:46:32 -0400 | [diff] [blame] | 286 | lowerCaseContent, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 287 | config.filters.wordFilter.words.loose, |
TheCodedProf | 21d4b0f | 2023-04-22 21:02:51 -0400 | [diff] [blame] | 288 | config.filters.wordFilter.words.strict |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 289 | ); |
| 290 | if (check !== null) { |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 291 | messageException(message.guild.id, message.channel.id, message.id); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 292 | await message.delete(); |
| 293 | const data = { |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 294 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 295 | type: "messageDelete", |
| 296 | displayName: "Message Deleted", |
| 297 | calculateType: "autoModeratorDeleted", |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 298 | color: NucleusColors.red, |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 299 | emoji: "MESSAGE.DELETE", |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 300 | timestamp: Date.now() |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 301 | }, |
| 302 | separate: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 303 | start: |
| 304 | filter + |
| 305 | " Message contained filtered word\n\n" + |
TheCodedProf | 22586d5 | 2023-04-23 16:46:32 -0400 | [diff] [blame] | 306 | (lowerCaseContent ? `**Message:**\n\`\`\`${message.content}\`\`\`` : "**Message:** *Message had no content*") |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 307 | }, |
| 308 | list: list, |
| 309 | hidden: { |
| 310 | guild: message.channel.guild.id |
| 311 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 312 | }; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 313 | return log(data); |
| 314 | } |
| 315 | } |
| 316 | |
TheCodedProf | c7e8ef1 | 2023-04-22 22:28:11 -0400 | [diff] [blame] | 317 | if ( |
| 318 | config.filters.pings.everyone && |
| 319 | message.mentions.everyone && |
| 320 | !checkUserForExceptions(message.member!, config.filters.pings.allowed) |
| 321 | ) { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 322 | if (!(await isLogging(message.guild.id, "messageMassPing"))) return; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 323 | const data = { |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 324 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 325 | type: "everyonePing", |
| 326 | displayName: "Everyone Pinged", |
| 327 | calculateType: "messageMassPing", |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 328 | color: NucleusColors.yellow, |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 329 | emoji: "MESSAGE.PING.EVERYONE", |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 330 | timestamp: Date.now() |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 331 | }, |
| 332 | separate: { |
TheCodedProf | 22586d5 | 2023-04-23 16:46:32 -0400 | [diff] [blame] | 333 | start: lowerCaseContent ? `**Message:**\n\`\`\`${message.content}\`\`\`` : "**Message:** *Message had no content*" |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 334 | }, |
| 335 | list: list, |
| 336 | hidden: { |
| 337 | guild: message.channel.guild.id |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 338 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 339 | }; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 340 | return log(data); |
| 341 | } |
TheCodedProf | c7e8ef1 | 2023-04-22 22:28:11 -0400 | [diff] [blame] | 342 | if (config.filters.pings.roles && !checkUserForExceptions(message.member!, config.filters.pings.allowed)) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 343 | for (const roleId in message.mentions.roles) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 344 | if (!config.filters.pings.allowed.roles.includes(roleId)) { |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 345 | messageException(message.guild.id, message.channel.id, message.id); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 346 | await message.delete(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 347 | if (!(await isLogging(message.guild.id, "messageMassPing"))) return; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 348 | const data = { |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 349 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 350 | type: "rolePing", |
| 351 | displayName: "Role Pinged", |
| 352 | calculateType: "messageMassPing", |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 353 | color: NucleusColors.yellow, |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 354 | emoji: "MESSAGE.PING.ROLE", |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 355 | timestamp: Date.now() |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 356 | }, |
| 357 | separate: { |
TheCodedProf | 22586d5 | 2023-04-23 16:46:32 -0400 | [diff] [blame] | 358 | start: lowerCaseContent |
| 359 | ? `**Message:**\n\`\`\`${message.content}\`\`\`` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 360 | : "**Message:** *Message had no content*" |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 361 | }, |
| 362 | list: list, |
| 363 | hidden: { |
| 364 | guild: message.channel.guild.id |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 365 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 366 | }; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 367 | return log(data); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 368 | } |
| 369 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 370 | } |
TheCodedProf | c7e8ef1 | 2023-04-22 22:28:11 -0400 | [diff] [blame] | 371 | if ( |
| 372 | message.mentions.users.size >= config.filters.pings.mass && |
| 373 | config.filters.pings.mass && |
| 374 | !checkUserForExceptions(message.member!, config.filters.pings.allowed) |
| 375 | ) { |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 376 | messageException(message.guild.id, message.channel.id, message.id); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 377 | await message.delete(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 378 | if (!(await isLogging(message.guild.id, "messageMassPing"))) return; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 379 | const data = { |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 380 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 381 | type: "massPing", |
| 382 | displayName: "Mass Ping", |
| 383 | calculateType: "messageMassPing", |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 384 | color: NucleusColors.yellow, |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 385 | emoji: "MESSAGE.PING.MASS", |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 386 | timestamp: Date.now() |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 387 | }, |
| 388 | separate: { |
TheCodedProf | 22586d5 | 2023-04-23 16:46:32 -0400 | [diff] [blame] | 389 | start: lowerCaseContent ? `**Message:**\n\`\`\`${message.content}\`\`\`` : "**Message:** *Message had no content*" |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 390 | }, |
| 391 | list: list, |
| 392 | hidden: { |
| 393 | guild: message.channel.guild.id |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 394 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 395 | }; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 396 | return log(data); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 397 | } |
| 398 | } |