better work
This commit is contained in:
parent
ff251c239f
commit
9df17b4a9d
|
@ -18,11 +18,29 @@ class Bot {
|
||||||
partials: ['CHANNEL', 'MESSAGE']
|
partials: ['CHANNEL', 'MESSAGE']
|
||||||
});
|
});
|
||||||
|
|
||||||
// Initialize command manager
|
// Add reference to this bot instance on the client for access from commands
|
||||||
|
this.client.bot = this;
|
||||||
|
|
||||||
|
// THIS IS IMPORTANT: Make sure CommandManager is initialized AFTER the client
|
||||||
this.commandManager = new CommandManager(this.client);
|
this.commandManager = new CommandManager(this.client);
|
||||||
|
|
||||||
// Authorized user ID - CHANGE THIS to your Discord user ID
|
// Authorized users for commands - Parse comma-separated list from env variable
|
||||||
this.authorizedUserId = process.env.AUTHORIZED_USER_ID;
|
this.authorizedUserIds = process.env.AUTHORIZED_USER_IDS
|
||||||
|
? process.env.AUTHORIZED_USER_IDS.split(',').map(id => id.trim())
|
||||||
|
: [];
|
||||||
|
|
||||||
|
// For backward compatibility, add the old env var if it exists
|
||||||
|
if (process.env.AUTHORIZED_USER_ID && !this.authorizedUserIds.includes(process.env.AUTHORIZED_USER_ID)) {
|
||||||
|
this.authorizedUserIds.push(process.env.AUTHORIZED_USER_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse notification recipient IDs (separate from command authorization)
|
||||||
|
this.notificationRecipientIds = process.env.NOTIFICATION_USER_IDS ?
|
||||||
|
process.env.NOTIFICATION_USER_IDS.split(',').map(id => id.trim()) :
|
||||||
|
this.authorizedUserIds; // Default to authorized users if not specified
|
||||||
|
|
||||||
|
console.log(`Authorized users configured: ${this.authorizedUserIds.length}`);
|
||||||
|
console.log(`Notification recipients configured: ${this.notificationRecipientIds.length}`);
|
||||||
|
|
||||||
// Setup temp directory
|
// Setup temp directory
|
||||||
this.setupTempDirectory();
|
this.setupTempDirectory();
|
||||||
|
@ -55,15 +73,6 @@ class Bot {
|
||||||
// Only register global commands for direct messages
|
// Only register global commands for direct messages
|
||||||
await this.commandManager.registerGlobalCommands();
|
await this.commandManager.registerGlobalCommands();
|
||||||
|
|
||||||
// Initialize and start the notification service
|
|
||||||
this.notificationService = new NotificationService(this.client, {
|
|
||||||
checkInterval: process.env.STATUS_CHECK_INTERVAL ? parseInt(process.env.STATUS_CHECK_INTERVAL) : 5000,
|
|
||||||
statusEndpoint: process.env.STATUS_ENDPOINT || 'https://blahaj.tr:2589/status'
|
|
||||||
});
|
|
||||||
|
|
||||||
await this.notificationService.initialize();
|
|
||||||
this.notificationService.start();
|
|
||||||
|
|
||||||
// Send startup notification
|
// Send startup notification
|
||||||
await this.sendStartupNotification();
|
await this.sendStartupNotification();
|
||||||
});
|
});
|
||||||
|
@ -71,7 +80,7 @@ class Bot {
|
||||||
// Interaction event
|
// Interaction event
|
||||||
this.client.on("interactionCreate", async (interaction) => {
|
this.client.on("interactionCreate", async (interaction) => {
|
||||||
// Only process commands if the user is authorized
|
// Only process commands if the user is authorized
|
||||||
if (interaction.user.id !== this.authorizedUserId) {
|
if (!this.authorizedUserIds.includes(interaction.user.id)) {
|
||||||
console.log(`Unauthorized access attempt by ${interaction.user.tag} (${interaction.user.id})`);
|
console.log(`Unauthorized access attempt by ${interaction.user.tag} (${interaction.user.id})`);
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: "You are not authorized to use this bot.",
|
content: "You are not authorized to use this bot.",
|
||||||
|
@ -108,11 +117,6 @@ class Bot {
|
||||||
name: "Relative Time",
|
name: "Relative Time",
|
||||||
value: `<t:${Math.floor(Date.now() / 1000)}:R>`,
|
value: `<t:${Math.floor(Date.now() / 1000)}:R>`,
|
||||||
inline: true
|
inline: true
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Status Monitoring",
|
|
||||||
value: this.notificationService?.isRunning ? "✅ Active" : "❌ Inactive",
|
|
||||||
inline: true
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
footer: {
|
footer: {
|
||||||
|
@ -120,23 +124,14 @@ class Bot {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Only notify the authorized user
|
// Notify all recipients
|
||||||
try {
|
for (const userId of this.notificationRecipientIds) {
|
||||||
const owner = await this.client.users.fetch(this.authorizedUserId);
|
|
||||||
await owner.send({ embeds: [startupEmbed] });
|
|
||||||
console.log(`Sent startup notification to authorized user: ${owner.tag}`);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Failed to send startup notification to authorized user:", error.message);
|
|
||||||
console.log("This is not critical - the bot will still function normally");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Also notify in status channel if configured
|
|
||||||
if (this.notificationService?.statusChannel) {
|
|
||||||
try {
|
try {
|
||||||
await this.notificationService.statusChannel.send({ embeds: [startupEmbed] });
|
const user = await this.client.users.fetch(userId);
|
||||||
console.log(`Sent startup notification to status channel: ${this.notificationService.statusChannel.name}`);
|
await user.send({ embeds: [startupEmbed] });
|
||||||
|
console.log(`Sent startup notification to recipient: ${user.tag}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to send startup notification to status channel:", error.message);
|
console.error(`Failed to send startup notification to user ${userId}:`, error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,13 +74,8 @@ class CommandManager {
|
||||||
async handleInteraction(interaction) {
|
async handleInteraction(interaction) {
|
||||||
if (!interaction.isChatInputCommand()) return;
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
// Double-check authorization
|
// We don't need to double-check authorization here since Bot.js already checks
|
||||||
if (interaction.user.id !== this.authorizedUserId) {
|
// This avoids potential inconsistencies in the authorization check
|
||||||
return interaction.reply({
|
|
||||||
content: "You are not authorized to use this command.",
|
|
||||||
ephemeral: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const command = this.commands.get(interaction.commandName);
|
const command = this.commands.get(interaction.commandName);
|
||||||
if (!command) return;
|
if (!command) return;
|
||||||
|
|
Loading…
Reference in a new issue