a
This commit is contained in:
parent
7ca886aa2e
commit
e0efd97621
4 changed files with 634 additions and 23 deletions
|
|
@ -1,4 +1,4 @@
|
|||
const { Collection, REST, Routes } = require('discord.js');
|
||||
const { Collection, REST, Routes, SlashCommandBuilder } = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
|
|
@ -9,6 +9,9 @@ class CommandManager {
|
|||
this.commandFolders = ['info', 'system']; // Only include info and system commands
|
||||
this.rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN);
|
||||
this.authorizedUserId = process.env.AUTHORIZED_USER_ID;
|
||||
|
||||
// Add this line to load commands when the CommandManager is created
|
||||
this.loadCommands();
|
||||
}
|
||||
|
||||
async loadCommands() {
|
||||
|
|
@ -48,26 +51,35 @@ class CommandManager {
|
|||
|
||||
async registerGlobalCommands() {
|
||||
try {
|
||||
await this.loadCommands();
|
||||
console.log("Registering global commands...");
|
||||
|
||||
if (this.commands.size === 0) {
|
||||
console.log("No commands to register.");
|
||||
return;
|
||||
}
|
||||
const commandsData = this.commands.map(command => {
|
||||
const data = {
|
||||
name: command.name,
|
||||
description: command.description,
|
||||
options: command.options || [],
|
||||
// Add these lines for global availability in all contexts
|
||||
integration_types: [1], // Add integration type for global availability
|
||||
contexts: [0, 1, 2], // Available in all contexts (DM, GROUP_DM, GUILD)
|
||||
};
|
||||
|
||||
// If the command has an addOptions method, call it
|
||||
if (typeof command.addOptions === 'function') {
|
||||
data.options = command.addOptions(new SlashCommandBuilder()).options;
|
||||
}
|
||||
|
||||
return data;
|
||||
});
|
||||
|
||||
const commandsData = this.commands.map(command => command.toJSON());
|
||||
|
||||
console.log(`Started refreshing ${commandsData.length} application (/) commands.`);
|
||||
|
||||
// Register as global commands for DMs
|
||||
const data = await this.rest.put(
|
||||
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN);
|
||||
await rest.put(
|
||||
Routes.applicationCommands(this.client.user.id),
|
||||
{ body: commandsData },
|
||||
);
|
||||
|
||||
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
|
||||
console.log(`Successfully registered ${commandsData.length} global commands`);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
console.error('Error registering global commands:', error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -97,6 +109,22 @@ class CommandManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
async handleAutocomplete(interaction) {
|
||||
const command = this.commands.get(interaction.commandName);
|
||||
|
||||
if (!command || typeof command.handleAutocomplete !== 'function') {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await command.handleAutocomplete(interaction);
|
||||
} catch (error) {
|
||||
console.error(`Error handling autocomplete for ${interaction.commandName}:`, error);
|
||||
// Respond with empty array as fallback
|
||||
await interaction.respond([]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CommandManager;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,28 @@ const axios = require('axios');
|
|||
class NotificationService {
|
||||
constructor(client, options = {}) {
|
||||
this.client = client;
|
||||
this.authorizedUserId = 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()) :
|
||||
[];
|
||||
|
||||
// For backward compatibility - if no notification IDs specified, use authorized IDs
|
||||
if (this.notificationRecipientIds.length === 0) {
|
||||
// Use the bot's authorizedUserIds as fallback
|
||||
this.notificationRecipientIds = client.bot.authorizedUserIds ||
|
||||
(process.env.AUTHORIZED_USER_IDS ?
|
||||
process.env.AUTHORIZED_USER_IDS.split(',').map(id => id.trim()) :
|
||||
[]);
|
||||
|
||||
// Add legacy single user ID for backward compatibility
|
||||
if (process.env.AUTHORIZED_USER_ID && !this.notificationRecipientIds.includes(process.env.AUTHORIZED_USER_ID)) {
|
||||
this.notificationRecipientIds.push(process.env.AUTHORIZED_USER_ID);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Notification recipients configured: ${this.notificationRecipientIds.length}`);
|
||||
|
||||
this.statusChannel = null;
|
||||
this.checkInterval = options.checkInterval || 10000; // Changed to 10 seconds default
|
||||
this.statusEndpoint = options.statusEndpoint || 'https://blahaj.tr:2589/status';
|
||||
|
|
@ -263,14 +284,14 @@ class NotificationService {
|
|||
}
|
||||
}
|
||||
|
||||
// Send to owner
|
||||
if (this.authorizedUserId) {
|
||||
// Send to all notification recipients
|
||||
for (const userId of this.notificationRecipientIds) {
|
||||
try {
|
||||
const owner = await this.client.users.fetch(this.authorizedUserId);
|
||||
await owner.send({ embeds: [embed] });
|
||||
console.log('Status change notification sent to owner');
|
||||
const user = await this.client.users.fetch(userId);
|
||||
await user.send({ embeds: [embed] });
|
||||
console.log(`Status change notification sent to recipient: ${user.tag}`);
|
||||
} catch (error) {
|
||||
console.error(`Failed to send status notification to owner: ${error.message}`);
|
||||
console.error(`Failed to send status notification to user ${userId}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue