Skip to content

Commit 5afb2cd

Browse files
committed
add: Added new script for updating logs
1 parent 2f5494f commit 5afb2cd

File tree

2 files changed

+134
-1
lines changed

2 files changed

+134
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"update-ytdl-core": "node src/scripts/ytdlUpdater.js",
1818
"setup-env:prod": "&& node src/scripts/setupEnvFile.js",
1919
"setup-env:dev": "node src/scripts/setupEnvFile.js setup-env:dev",
20-
"commit": "node src/scripts/commitRunner.js"
20+
"commit": "node src/scripts/commitRunner.js",
21+
"log-setup": "node src/scripts/setupLogs.js"
2122
},
2223
"keywords": [],
2324
"author": "",

src/scripts/setupLogs.js

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
const { color, getTimestamp } = require("../utils/loggingEffects");
4+
5+
console.log(`${color.pink}[${getTimestamp()}] ${color.reset}[SET_AUDIT_LOGS] Updating discord-logs module...`);
6+
7+
const filePath = path.join(__dirname, "../../node_modules/discord-logs/lib/index.js");
8+
const newContent = `"use strict";
9+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
10+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
11+
return new (P || (P = Promise))(function (resolve, reject) {
12+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
13+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
14+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
15+
step((generator = generator.apply(thisArg, _arguments || [])).next());
16+
});
17+
};
18+
19+
const color = {
20+
red: '\\x1b[31m',
21+
orange: '\\x1b[38;5;202m',
22+
yellow: '\\x1b[33m',
23+
green: '\\x1b[32m',
24+
blue: '\\x1b[34m',
25+
reset: '\\x1b[0m',
26+
pink: '\\x1b[38;5;213m'
27+
}
28+
29+
function getTimestamp() {
30+
const date = new Date();
31+
const year = date.getFullYear();
32+
const month = date.getMonth() + 1;
33+
const day = String(date.getDate()).padStart(2, "0");
34+
const hours = String(date.getHours()).padStart(2, "0");
35+
const minutes = String(date.getMinutes()).padStart(2, "0");
36+
const seconds = String(date.getSeconds()).padStart(2, "0");
37+
return \`\${year}-\${month}-\${day} \${hours}:\${minutes}:\${seconds}\`;
38+
}
39+
40+
const discord_js_1 = require("discord.js");
41+
const handlers_1 = require("./handlers");
42+
let eventRegistered = false;
43+
module.exports = (client, options) => __awaiter(void 0, void 0, void 0, function* () {
44+
if (eventRegistered)
45+
return;
46+
eventRegistered = true;
47+
const intents = new discord_js_1.IntentsBitField(client.options.intents);
48+
/* HANDLE GUILDS EVENTS */
49+
if (intents.has(discord_js_1.IntentsBitField.Flags.Guilds)) {
50+
if (options === null || options === void 0 ? void 0 : options.debug)
51+
console.log(\`\${color.pink}[\${getTimestamp()}] \${color.reset}[AUDIT_LOGS] ChannelUpdate event handler registered.\`);
52+
client.on('channelUpdate', (oldChannel, newChannel) => {
53+
(0, handlers_1.handleChannelUpdateEvent)(client, oldChannel, newChannel);
54+
});
55+
if (options === null || options === void 0 ? void 0 : options.debug)
56+
console.log(\`\${color.pink}[\${getTimestamp()}] \${color.reset}[AUDIT_LOGS] GuildUpdate event handler registered.\`);
57+
client.on('guildUpdate', (oldGuild, newGuild) => {
58+
(0, handlers_1.handleGuildUpdateEvent)(client, oldGuild, newGuild);
59+
});
60+
if (options === null || options === void 0 ? void 0 : options.debug)
61+
console.log(\`\${color.pink}[\${getTimestamp()}] \${color.reset}[AUDIT_LOGS] RoleUpdate event handler registered.\`);
62+
client.on('roleUpdate', (oldRole, newRole) => {
63+
(0, handlers_1.handleRoleUpdateEvent)(client, oldRole, newRole);
64+
});
65+
if (options === null || options === void 0 ? void 0 : options.debug)
66+
console.log(\`\${color.pink}[\${getTimestamp()}] \${color.reset}[AUDIT_LOGS] ThreadUpdate event handler registered.\`);
67+
client.on('threadUpdate', (oldThread, newThread) => {
68+
(0, handlers_1.handleThreadChannelUpdateEvent)(client, oldThread, newThread);
69+
});
70+
}
71+
else {
72+
if (options === null || options === void 0 ? void 0 : options.debug)
73+
console.log('channelUpdate, guildUpdate, roleUpdate and threadUpdate event handlers not registered (missing Guilds intent).');
74+
}
75+
/* HANDLE MEMBER EVENTS */
76+
if (intents.has(discord_js_1.IntentsBitField.Flags.GuildMembers)) {
77+
if (options === null || options === void 0 ? void 0 : options.debug)
78+
console.log(\`\${color.pink}[\${getTimestamp()}] \${color.reset}[AUDIT_LOGS] GuildMemberUpdate event handler registered.\`);
79+
client.on('guildMemberUpdate', (oldMember, newMember) => {
80+
(0, handlers_1.handleGuildMemberUpdateEvent)(client, oldMember, newMember);
81+
});
82+
if (options === null || options === void 0 ? void 0 : options.debug)
83+
console.log(\`\${color.pink}[\${getTimestamp()}] \${color.reset}[AUDIT_LOGS] UserUpdate event handler registered.\`);
84+
client.on('userUpdate', (oldUser, newUser) => {
85+
(0, handlers_1.handleUserUpdateEvent)(client, oldUser, newUser);
86+
});
87+
}
88+
else {
89+
if (options === null || options === void 0 ? void 0 : options.debug)
90+
console.log('guildMemberUpdate, userUpdate event handlers not registered (missing GuildMembers intent).');
91+
}
92+
/* HANDLE MESSAGE UPDATE EVENTS */
93+
if (intents.has(discord_js_1.IntentsBitField.Flags.GuildMessages && discord_js_1.IntentsBitField.Flags.MessageContent)) {
94+
if (options === null || options === void 0 ? void 0 : options.debug)
95+
console.log(\`\${color.pink}[\${getTimestamp()}] \${color.reset}[AUDIT_LOGS] MessageUpdate event handler registered.\`);
96+
client.on('messageUpdate', (oldMessage, newMessage) => {
97+
(0, handlers_1.handleMessageUpdateEvent)(client, oldMessage, newMessage);
98+
});
99+
}
100+
else {
101+
if (options === null || options === void 0 ? void 0 : options.debug)
102+
console.log('messageUpdate event handler not registered (missing GuildMessages or MessageContent intent).');
103+
}
104+
/* HANDLE PRESENCE UPDATE EVENTS */
105+
if (intents.has(discord_js_1.IntentsBitField.Flags.GuildPresences)) {
106+
if (options === null || options === void 0 ? void 0 : options.debug)
107+
console.log(\`\${color.pink}[\${getTimestamp()}] \${color.reset}[AUDIT_LOGS] PresenceUpdate event handler registered.\`);
108+
client.on('presenceUpdate', (oldPresence, newPresence) => {
109+
(0, handlers_1.handlePresenceUpdateEvent)(client, oldPresence, newPresence);
110+
});
111+
}
112+
else {
113+
if (options === null || options === void 0 ? void 0 : options.debug)
114+
console.log('presenceUpdate event handler not registered (missing GuildPresences intent).');
115+
}
116+
/* HANDLE VOICE STATE UPDATE */
117+
if (intents.has(discord_js_1.IntentsBitField.Flags.GuildVoiceStates)) {
118+
if (options === null || options === void 0 ? void 0 : options.debug)
119+
console.log(\`\${color.pink}[\${getTimestamp()}] \${color.reset}[AUDIT_LOGS] VoiceStateUpdate event handler registered.\`);
120+
client.on('voiceStateUpdate', (oldState, newState) => {
121+
(0, handlers_1.handleVoiceStateUpdateEvent)(client, oldState, newState);
122+
});
123+
}
124+
else {
125+
if (options === null || options === void 0 ? void 0 : options.debug)
126+
console.log('voiceStateUpdate event handler not registered (missing GuildVoiceStates intent).');
127+
}
128+
});
129+
`;
130+
131+
fs.writeFileSync(filePath, newContent, "utf8");
132+
console.log(`${color.pink}[${getTimestamp()}] ${color.reset}[SET_AUDIT_LOGS] Updated discord-logs module.`);

0 commit comments

Comments
 (0)