-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
331 lines (287 loc) · 11.7 KB
/
server.js
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
const { Client, Intents, MessageEmbed } = require('discord.js');
class Main {
constructor(config) {
this.config = config;
this.client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_PRESENCES,
Intents.FLAGS.GUILD_MESSAGES,
],
});
this.loadcache = false;
this.channelsCache = {};
this.setupEventListeners();
}
setupEventListeners() {
this.client.once('ready', () => {
console.log('The script loaded the discord.js module!');
this.updateCache();
setInterval(() => this.updateCache(), 15 * 60 * 1000); //15 minutes
});
}
login() {
this.client.login(this.config.discordBotToken);
}
/**
* @param {string} playerName - The name of the player.
* @param {Array} foundMessages - message found by the script
*/
async sendmembed(playerName, foundMessages) {
const sendChannel = this.client.channels.cache.get(this.config.sendChannelId);
if (!sendChannel) {
console.warn(`Channel with ID ${this.config.sendChannelId} does not exist!`);
return;
}
const embedConfig = this.config.embedConfig;
const embed = new MessageEmbed()
.setTitle(embedConfig.title)
.setDescription(embedConfig.descriptionTemplate.replace('{playerName}', playerName))
.setColor(embedConfig.color)
.setThumbnail(embedConfig.thumbnailUrl)
.setFooter({ text: embedConfig.footerText });
if (embedConfig.timestamp) {
embed.setTimestamp();
}
foundMessages.forEach(({ content, channelName, channelId, messageId, messageTime, identifiers }) => {
const link = `https://discord.com/channels/${this.config.houndsdiscord}/${channelId}/${messageId}`;
const identifierStrings = [];
for (const k in identifiers) {
if (identifiers.hasOwnProperty(k)) {
identifierStrings.push(...identifiers[k]);
}
}
embed.addField(
`**Channel**: ${channelName}`,
`[More](${link})\n\n**Message ID:** ${messageId}\n\n**Content:** ${content.substring(0, 300)}...\n\n**Detected Identifiers:** ${identifierStrings.join(', ')}\n\n**Message Date:** ${messageTime.toLocaleString()}`
);
});
try {
await sendChannel.send({ embeds: [embed] });
} catch (error) {
console.error(`Error sending message to channel ${sendChannel.id}:`, error);
}
}
async updateCache() {
this.loadcache = false;
const startTime = Date.now();
console.log('[2;37m[2;33m[Hounds all Server] [0m[2;37m[0m Updating cache...');
for (const channelId of this.config.checkChannels) {
console.log(`[2;37m[2;33m[Hounds all Server] [0m[2;37m[0m Fetching messages from channel: ${channelId}`);
const channel = await this.client.channels.fetch(channelId).catch(error => {
console.error(`Unable to fetch channel with ID ${channelId}:`, error);
});
if (!channel) {
console.warn(`Channel with ID ${channelId} does not exist or the bot does not have access!`);
continue;
}
try {
let messages = await this.fetchAllMessages(channel);
this.channelsCache[channelId] = messages;
console.log(`[2;37m[2;33m[Hounds all Server] [0m[2;37m[0m Cached ${messages.length} messages from channel ${channelId}.`);
} catch (error) {
console.error(`Error fetching messages for cache from channel ${channelId}:`, error);
}
}
const endTime = Date.now();
this.loadcache = true;
console.log(`[2;37m[2;33m[Hounds all Server] [0m[2;37m[0m Cache updated. Duration: ${(endTime - startTime) / 1000} seconds.`);
}
/**
* @param {Array} channel - channel info discord
* @returns {Array} - message found.
*/
async fetchAllMessages(channel) {
let allMessages = [];
let lastMessageId;
const endDateTimestamp = new Date(this.config.endDate).getTime();
while (1 > 0) {
const options = { limit: 100 };
if (lastMessageId) options.before = lastMessageId;
const messages = await channel.messages.fetch(options).catch(error => {
console.error(`Error fetching messages from channel ${channel.id}:`, error);
return null;
});
if (!messages || messages.size === 0) break;
messages.forEach(message => {
if (this.config.endDate && message.createdTimestamp < endDateTimestamp) return;
allMessages.push(message);
});
lastMessageId = messages.last()?.id;
if (!lastMessageId) break;
}
return allMessages;
}
/**
* @param {string} text - The text from which to extract identifiers.
* @returns {Array} - An array of extracted identifiers.
*/
checktext(text) {
const identp = {
steam: /steam:1[0-9a-f]+/gi,
discord: /discord:\d+/gi,
license: /license:[0-9a-f]+/gi,
xbl: /xbl:\d+/gi,
live: /live:\d+/gi,
fivem: /fivem:\d+/gi,
playerID: /Player ID:\s*(\d+)/gi,
rockstarLicense: /Licencja Rockstar:\s*(license:[0-9a-f]+)/gi,
tokens: /\b\d{17,19}\b/g
};
let i = {};
for (const [k, p] of Object.entries(identp)) {
const m = text.match(p);
if (m) {
i[k] = m;
}
}
return i;
}
/**
* @param {number} channelId - ID channel.
* @returns {Array} foundMessages - message found by the script
*/
async findIdentifiers(channelId, identifiers) {
let foundMessages = [];
const cachedMessages = this.channelsCache[channelId] || [];
for (const message of cachedMessages) {
const messageIdentifiers = this.checktext(message.content);
let found = this.checkidentifiers(messageIdentifiers, identifiers);
if (!found && message.embeds.length > 0) {
for (const embed of message.embeds) {
const embedText = `${embed.title || ''}\n${embed.description || ''}`;
const embedIdentifiers = this.checktext(embedText);
found = this.checkidentifiers(embedIdentifiers, identifiers);
if (found) {
break;
}
}
}
if (found) {
foundMessages.push({
content: message.content,
channelName: message.channel.name,
channelId: message.channel.id,
messageId: message.id,
messageTime: message.createdAt,
identifiers: messageIdentifiers
});
}
}
return foundMessages;
}
/**
* @param {Array} identifierGroups - Identifiers table.
* @returns {boolean}
*/
checkidentifiers(identifierGroups, identifiers) {
for (const itype in identifierGroups) {
if (identifierGroups.hasOwnProperty(itype)) {
const identifierArray = identifierGroups[itype];
if (Array.isArray(identifierArray)) {
for (const i of identifiers) {
if (identifierArray.includes(i)) {
return true;
}
}
}
}
}
return false;
}
/**
* @param {Array} identifiers - Identifiers table.
* @returns {boolean}
*/
filtr(identifiers, ipdisabled) {
return identifiers.filter(identifier => {
const isIP = identifier.startsWith("ip:");
return ipdisabled ? !isIP : true;
});
}
/**
* @param {number} player - ID players.
* @returns {Array} - table identifiers
*/
GetPlayerIdentifiers(player) {
const identifiers = Array.from(
{ length: GetNumPlayerIdentifiers(player) },
(_, i) => GetPlayerIdentifier(player, i)
);
const tokens = Array.from(
{ length: GetNumPlayerTokens(player) },
(_, i) => GetPlayerToken(player, i)
);
return this.filtr([...identifiers, ...tokens], config.ipdisable)
}
/**
* @param {Array} players - ID table players.
*/
async checkPlayers(players) {
for (const player of players) {
const identifiers = this.GetPlayerIdentifiers(player);
const playerName = GetPlayerName(player);
for (const checkChannelId of this.config.checkChannels) {
const found = await this.findIdentifiers(checkChannelId, identifiers);
if (found.length > 0) {
console.log(`Cheater Detected: ${playerName}`);
await this.sendmembed(`${playerName} (${player})`, found);
}
}
console.log(`Finished checking channels for player: ${playerName} (${player})`);
}
}
}
const config = {
"discordBotToken": "",
"sendChannelId": "",
"ipdisable": true,
"houndsdiscord": "829385448345305128",
"endDate": "2024-01-01",
"checkChannels": [
"1187831821396885657", // trujca
"829392430297382952", // cocorp
"829416209161519153", // realmrp
"991486546156998667", // grandrdm
"1113917598329999400", // 4rdm
"924794155669012501", // hyperp
"1112724890794074142", // adrenalinarp
"1124717448181063883", // onlyrp
"989979352169054209", // neonrp
"1015007025773678612", // 77rp
"999450502163075102", // nightsiderp
"995743748770242570", // betterside
"1020026499241349191", // waitrp
"1054901681286025349", // xenonrp
"1128082880111849502", // fazerp
"1132684812436643890", // wavesrp
"1120121781345333339", // flushrp
"1120992396868587640", // luna-rp
"1142245676344934410", // leangg
"1172601237238190181", // mystory
"1184187836166053908", // x-rp
"1184087452466544703", // continentalrp
"1183911527913361568", // exumarp
"1172600743144980623", // oslorp
"1084082698563358780", // richrp
"1109113316707663923", // 3rp
],
"embedConfig": {
"title": "Wykryto frajera!",
"descriptionTemplate": "Gracz **{playerName}** został wykryty jako cheater wypisane na hounds all!",
"color": "124304",
"thumbnailUrl": "https://i.imgur.com/VLnUaOz.png",
"footerText": "©️ Trujca.gg created by junredzikkk",
"timestamp": true
}
};
const script = new Main(config);
on('trujca:join', async (playerId) => { //rename esx:playerLoaded for the esx framework or another custom for your
const player = playerId;
const playersToCheck = [player];
if (script.loadcache) {
await script.checkPlayers(playersToCheck);
}
});
script.login();