forked from manishbhaiii/roxy-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
301 lines (247 loc) · 10.6 KB
/
index.js
File metadata and controls
301 lines (247 loc) · 10.6 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
require('dotenv').config();
const { Client } = require('discord.js-selfbot-v13');
const fs = require('fs');
const path = require('path');
const client = new Client({
checkUpdate: false
});
// Initialize music system
const Lavalink = require('./music/lavalink');
const queueManager = require('./music/queue');
// Initialize Lavalink if configured
let lavalink = null;
if (process.env.LAVALINK_WS && process.env.LAVALINK_REST && process.env.LAVALINK_PASSWORD) {
lavalink = new Lavalink({
restHost: process.env.LAVALINK_REST,
wsHost: process.env.LAVALINK_WS,
password: process.env.LAVALINK_PASSWORD,
clientName: process.env.CLIENT_NAME || 'RoxyPlus',
});
}
// Voice states storage
const voiceStates = {};
client.commands = new Map();
client.lavalink = lavalink;
client.queueManager = queueManager;
client.voiceStates = voiceStates;
// Allowed Users Logic
const allowedManager = require('./commands/allowedManager');
function isAllowedUser(userId) {
// Always allow the bot owner (the user logged in)
if (userId === client.user.id) return true;
return allowedManager.isAllowed(userId);
}
const commandsPath = path.join(__dirname, 'commands');
if (fs.existsSync(commandsPath)) {
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
try {
const command = require(path.join(commandsPath, file));
if (command.name) {
client.commands.set(command.name, command);
}
} catch (error) {
console.error('Error loading command ' + file + ':', error);
}
}
}
const dashboard = require('./dashboard/index');
client.on('ready', () => {
console.log('Logged in as ' + client.user.tag);
console.log('User ID: ' + client.user.id);
console.log('Roxy+ is ready!');
console.log('Loaded ' + client.commands.size + ' commands');
// Connect to Lavalink if available
if (client.lavalink) {
client.lavalink.connect(client.user.id);
console.log('Connecting to Lavalink...');
}
// Initialize RPC
const rpcManager = require('./commands/rpcManager');
rpcManager.initialize(client);
// Initialize Auto Reaction
const reactionManager = require('./commands/reactionManager');
reactionManager.initialize(client);
// Initialize AI System
const aiManager = require('./commands/aiManager');
aiManager.initialize(client);
// Initialize Status Manager
const statusManager = require('./commands/statusManager');
// Note: rpcManager.initialize already handles setting the initial merged presence
// Heartbeat to prevent status from disappearing (every 10 minutes)
setInterval(async () => {
const rpcManager = require('./commands/rpcManager');
const data = rpcManager.loadData();
await rpcManager.setPresence(client, data);
}, 10 * 60 * 1000);
// Initialize Mirror System
const mirrorManager = require('./commands/mirrorManager');
mirrorManager.initialize(client);
// Start Dashboard
dashboard(client);
});
// Voice state handling for Lavalink
if (client.lavalink) {
client.ws.on('VOICE_STATE_UPDATE', (packet) => {
if (packet.user_id !== client.user.id) return;
const guildId = packet.guild_id;
if (!voiceStates[guildId]) voiceStates[guildId] = {};
voiceStates[guildId].sessionId = packet.session_id;
console.log(`[Voice] State update for guild ${guildId}`);
});
client.ws.on('VOICE_SERVER_UPDATE', (packet) => {
const guildId = packet.guild_id;
if (!voiceStates[guildId]) voiceStates[guildId] = {};
voiceStates[guildId].token = packet.token;
voiceStates[guildId].endpoint = packet.endpoint;
console.log(`[Voice] Server update for guild ${guildId}`);
});
// Lavalink event handlers
client.lavalink.on('ready', () => {
console.log('[Lavalink] Session established');
});
client.lavalink.on('event', async (evt) => {
console.log(`[Lavalink Event] Type: ${evt.type}, Guild: ${evt.guildId}`);
if (evt.type === 'TrackEndEvent') {
if (evt.reason === 'finished' || evt.reason === 'loadFailed') {
const queue = queueManager.get(evt.guildId);
if (!queue) return;
if (queue.nowPlaying) {
queue.history.push(queue.nowPlaying);
}
const nextSong = queueManager.getNext(evt.guildId);
if (!nextSong) {
await client.lavalink.destroyPlayer(evt.guildId);
queueManager.delete(evt.guildId);
if (queue.textChannel) {
queue.textChannel.send('```Queue finished```');
}
return;
}
queue.nowPlaying = nextSong;
const voiceState = voiceStates[evt.guildId];
if (voiceState && voiceState.token && voiceState.sessionId && voiceState.endpoint) {
try {
await client.lavalink.updatePlayer(evt.guildId, nextSong, voiceState, {
volume: queue.volume,
filters: queue.filters
});
if (queue.textChannel) {
let nowPlayingMsg = '```\n';
nowPlayingMsg += '╭─[ NOW PLAYING ]─╮\n\n';
nowPlayingMsg += ` 🎵 ${nextSong.info.title}\n`;
nowPlayingMsg += ` 👤 ${nextSong.info.author}\n`;
nowPlayingMsg += '\n╰──────────────────────────────────╯\n```';
queue.textChannel.send(nowPlayingMsg);
}
} catch (err) {
console.error('[Auto-play Error]:', err);
if (queue.textChannel) {
queue.textChannel.send('```Error playing next song```');
}
}
}
}
}
});
client.lavalink.on('playerUpdate', (packet) => {
const queue = queueManager.get(packet.guildId);
if (queue && packet.state) {
queue.position = packet.state.position;
queue.lastUpdate = Date.now();
}
});
}
// AFK & Logging Logic
const respondedUsers = new Set();
// Clear responded users every 1 hour
setInterval(() => respondedUsers.clear(), 3600000);
client.on('messageCreate', async (message) => {
try {
if (!message.author) return;
// --- AFK & LOGGING SYSTEM ---
const mentionsMe = message.mentions.users.has(client.user.id);
const isDm = message.channel.type === 'DM';
if ((mentionsMe || isDm) && message.author.id !== client.user.id) {
// Read Settings
const afkPath = path.join(__dirname, 'data', 'afk.json');
const logPath = path.join(__dirname, 'data', 'afklog.json');
let afkData = { isOn: false, reason: '', logsEnabled: false };
if (fs.existsSync(afkPath)) {
afkData = JSON.parse(fs.readFileSync(afkPath, 'utf8'));
}
// 1. LOGGING (If enabled)
if (afkData.logsEnabled) {
let logs = [];
if (fs.existsSync(logPath)) {
logs = JSON.parse(fs.readFileSync(logPath, 'utf8'));
}
let cleanContent = message.content;
// 1. Clean User Mentions <@ID> or <@!ID>
cleanContent = cleanContent.replace(/<@!?(\d+)>/g, (match, id) => {
const user = client.users.cache.get(id);
return user ? `@${user.username}` : match;
});
// 2. Clean Role Mentions <@&ID>
cleanContent = cleanContent.replace(/<@&(\d+)>/g, (match, id) => {
const role = message.guild ? message.guild.roles.cache.get(id) : null;
return role ? `@${role.name}` : match;
});
// 3. Clean Channel Mentions <#ID>
cleanContent = cleanContent.replace(/<#(\d+)>/g, (match, id) => {
const channel = client.channels.cache.get(id);
return channel ? `#${channel.name}` : match;
});
// 4. Clean Custom Emojis <:name:ID>
cleanContent = cleanContent.replace(/<a?:(\w+):(\d+)>/g, ':$1:');
const logEntry = {
id: Date.now().toString(),
user: message.author.tag,
userId: message.author.id,
channel: isDm ? 'DM' : message.channel.name || 'Unknown',
guild: message.guild ? message.guild.name : 'Direct Message',
content: cleanContent,
time: new Date().toLocaleString(),
link: message.url
};
logs.unshift(logEntry);
if (logs.length > 50) logs = logs.slice(0, 50);
fs.writeFileSync(logPath, JSON.stringify(logs, null, 2));
}
// 2. AFK REPLY
if (afkData.isOn && !respondedUsers.has(message.author.id)) {
const reason = afkData.reason || "I'm currently AFK.";
try {
await message.reply(`**[AFK]** ${reason}`);
respondedUsers.add(message.author.id);
} catch (err) {
console.error('Failed to reply to AFK ping:', err);
}
}
}
// --- COMMAND HANDLER ---
const prefix = process.env.PREFIX || '!';
if (!message.content.startsWith(prefix)) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
if (!isAllowedUser(message.author.id)) {
return;
}
const command = client.commands.get(commandName);
if (!command) return;
await command.execute(message, args, client);
} catch (error) {
console.error('Error in messageCreate:', error);
}
});
process.on('unhandledRejection', error => {
console.error('Unhandled promise rejection:', error);
});
if (!process.env.TOKEN) {
console.error('Error: TOKEN not found in .env file');
process.exit(1);
}
client.login(process.env.TOKEN).catch(error => {
console.error('Failed to login:', error.message);
process.exit(1);
});