-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAntiGhostPing.js
More file actions
313 lines (296 loc) · 9.74 KB
/
AntiGhostPing.js
File metadata and controls
313 lines (296 loc) · 9.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
import { ChannelType, Events, Message } from "discord.js";
import { BryanBot } from "../../src/Modules/Structures/BryanBot.js";
import { Addon } from "../../src/Modules/Structures/Handlers/Addons.js";
import {
EventEmitter,
EventListener,
} from "../../src/Modules/Structures/Handlers/Events.js";
import Utils from "../../src/Modules/Utils.js";
import chalk from "chalk";
const addon = new Addon("AntiGhostPing", "v1.0.0"),
addonConfig = {
Config: {
"~00": "Ignore GhostPings section",
Ignored: {
"~01": "GhostPing from these users won't be detected",
Users: ["simonb50"],
"~02": "GhostPings from people, who have these roles won't be detected",
Roles: ["Admin"],
"~03": "GhostPings in these channels won't be detected",
Channels: ["news"],
"~04": "GhostPing in these categories won't be detected",
Categories: ["tickets"],
"~05": "Should GhostPings from bots be ignored?",
Bots: true,
},
"~07": "Which GhostPings should be detected?",
Mentions: {
"~08": "Users' pings detection",
User: true,
"~09": "Roles' pings detection",
Role: true,
"~10": "@everyone and @here pings detection",
Everyone: true,
},
"~11": "Logging options",
Logging: {
"~12":
"Should info about GhostPing be send in channel, where it was detected?",
MessageChannel: true,
"~13": "Admin logging options",
Logs: {
"~14": "Should all GhostPing be sent into logs channel?",
Enabled: false,
"~15": "Admin logging channel, where GhostPings should be send",
Channel: "ghost-pings",
},
},
},
Language: {
"~01": "Messages used by addon.",
"~02": "It's RECOMENDED to use placeholders here.",
Messages: {
"~03": "Ghots Ping Message",
"~04": "It's recomended to use these placeholders:",
"~05":
"- Message Author variables(like {user-username}, {user-pfp} etc.)",
"~06": "- {message} - Ghots Ping message content",
GhostPing: {
Content: "👻 Ghost Ping detected 👻",
Embeds: [
{
Title: "Ghost Ping Found!",
Color: "#FFFF00",
Author: "{user-tag}",
AuthorIcon: "{user-pfp}",
Fields: [
{
Name: "User",
Value: "{user-mention}",
Inline: true,
},
{
Name: "Message",
Value: "{message}",
Inline: true,
},
],
Thumbnail: "https://i.imgur.com/lb4kKPU.png",
Footer: "{brand-name}",
FooterIcon: "{brand-logo}",
Timestamp: true,
},
],
},
"~07": "GhostPing log message - only works, when enabled",
"~08":
"You can use {channel-?} variables, to get ghostping channel info",
GhostPingLog: {
Embeds: [
{
Title: "Ghost Ping Found!",
Color: "#FFFF00",
Author: "{user-tag}",
AuthorIcon: "{user-pfp}",
Fields: [
{
Name: "User",
Value: "{user-mention}",
Inline: true,
},
{
Name: "Message",
Value: "{message}",
Inline: true,
},
{
Name: "Channel",
Value: "{channel-mention}",
Inline: true,
},
],
Thumbnail: "https://i.imgur.com/lb4kKPU.png",
Footer: "{brand-name}",
FooterIcon: "{brand-logo}",
Timestamp: true,
},
],
},
},
},
};
/** @type {addonConfig} */
const { Config, Language } = addon.customConfig(addonConfig);
const Logger = {
Banner: chalk.hex("#ffffff").bold("[AntiGhostPing] "),
logInfo: (...i) => Utils.logger.info(Logger.Banner, ...i),
logWarning: (...w) => Utils.logger.warn(Logger.Banner, ...w),
logError: (...e) => Utils.logger.error(Logger.Banner, ...e),
};
addon
.setDeveloper("SimonB50")
.setDiscord("https://discord.gg/SgUjx2KJUd")
.setDocs("https://simonb50.gitbook.io/docs/");
addon.setExecute(async (manager) => {
new EventListener(
Events.MessageDelete,
/**
* Message delete event
* @param {BryanBot} manager
* @param {Message} message
*/
async (manager, message) => {
// Check if channel is DM
if (message.channel.type === "DM") return;
// Check for pings
if (
!(Config.Mentions.User && message.mentions.users.first()) &&
!(Config.Mentions.Role && message.mentions.roles.first()) &&
!(Config.Mentions.Everyone && message.mentions.everyone)
)
return;
// Check if ignored
const ignored = [false];
if (
Config.Ignored.Users.includes(message.author.id) ||
Config.Ignored.Users.includes(message.author.username)
)
ignored.push(true);
if (Utils.hasPermission(Config.Ignored.Roles, message.member))
ignored.push(true);
if (
Config.Ignored.Channels.includes(message.channel.id) ||
Config.Ignored.Channels.includes(message.channel.name)
)
ignored.push(true);
if (
message.channel.parent &&
(Config.Ignored.Categories.includes(message.channel.parent.id) ||
Config.Ignored.Categories.includes(message.channel.parent.name))
)
ignored.push(true);
if (Config.Ignored.Bots && message.author.bot) ignored.push(true);
if (ignored.includes(true)) return;
// Emit GhostPing event
new EventEmitter("ghostPing", message);
}
);
new EventListener(
Events.MessageUpdate,
/**
* Message update event
* @param {BryanBot} manager
* @param {Message} oldMessage
* @param {Message} newMessage
*/
async (manager, oldMessage, newMessage) => {
// Check if channel is DM
if (oldMessage.channel.type === "DM") return;
// Check for deleted mentions
if (
!(
Config.Mentions.User &&
oldMessage.mentions.members.some((x) => !newMessage.mentions.has(x))
) &&
!(
Config.Mentions.Role &&
oldMessage.mentions.roles.some((x) => !newMessage.mentions.has(x))
) &&
!(
Config.Mentions.Everyone &&
oldMessage.mentions.everyone &&
!newMessage.mentions.everyone
)
)
return;
// Check if ignored
const ignored = [false];
if (
Config.Ignored.Users.includes(oldMessage.author.id) ||
Config.Ignored.Users.includes(oldMessage.author.username)
)
ignored.push(true);
if (Utils.hasPermission(Config.Ignored.Roles, newMessage.member))
ignored.push(true);
if (
Config.Ignored.Channels.includes(oldMessage.channel.id) ||
Config.Ignored.Channels.includes(oldMessage.channel.name)
)
ignored.push(true);
if (
oldMessage.channel.parent &&
(Config.Ignored.Categories.includes(oldMessage.channel.parent.id) ||
Config.Ignored.Categories.includes(oldMessage.channel.parent.name))
)
ignored.push(true);
if (Config.Ignored.Bots && oldMessage.author.bot) ignored.push(true);
if (ignored.includes(true)) return;
// Emit ghostPing event
new EventEmitter("ghostPing", oldMessage);
}
);
new EventListener(
"ghostPing",
/**
* GhostPing event
* @param {BryanBot} manager
* @param {Message} message
*/
async (manager, message) => {
if (Config.Logging.MessageChannel)
message.channel
.send(
Utils.setupMessage({
configPath: Language.Messages.GhostPing,
variables: [
{
searchFor: /{message}/g,
replaceWith:
(message.mentions.repliedUser
? "↳ <@" + message.mentions.repliedUser.id + "> | "
: "") + message.content,
},
...Utils.userVariables(message.member),
...Utils.botVariables(manager),
...Utils.channelVariables(message.channel),
...Utils.guildVariables(message.guild),
],
})
)
.catch((e) => Logger.logError(e.message));
if (Config.Logging.Logs.Enabled) {
const channel = Utils.findChannel(
ChannelType.GuildText,
message.guild,
Config.Logging.Logs.Channel
);
if (!channel)
return Logger.logError(
"Invalid Logs channel has been provided in addon configs. GhostPing logs won't be send."
);
channel
.send(
Utils.setupMessage({
configPath: Language.Messages.GhostPingLog,
variables: [
{
searchFor: /{message}/g,
replaceWith:
(message.mentions.repliedUser
? "↳ <@" + message.mentions.repliedUser.id + "> | "
: "") + message.content,
},
...Utils.userVariables(message.member),
...Utils.botVariables(manager),
...Utils.channelVariables(message.channel),
...Utils.guildVariables(message.guild),
],
})
)
.catch((e) => Logger.logError(e.message));
}
}
);
Logger.logInfo(`Addon loaded! Author: ${chalk.bold("Simonb50")}`);
});
export default addon;