64 lines
2.4 KiB
JavaScript
64 lines
2.4 KiB
JavaScript
const { ActivityType } = require('discord.js');
|
|
const deployCommands = require('../deploy-commands');
|
|
const api = require('../api');
|
|
|
|
module.exports = {
|
|
name: 'clientReady',
|
|
once: true,
|
|
async execute(client) {
|
|
const guildIds = client.guilds.cache.map(guild => guild.id);
|
|
if (guildIds.length > 0) {
|
|
// Deploy commands for all guilds in parallel, but only log a single summary
|
|
try {
|
|
await Promise.all(guildIds.map(id => deployCommands(id)));
|
|
console.log(`🔁 Refreshed application commands for ${guildIds.length} guild(s)`);
|
|
} catch (e) {
|
|
console.error('Error refreshing application commands:', e && e.message ? e.message : e);
|
|
}
|
|
}
|
|
|
|
// Reconcile invites for all guilds to detect invites deleted while bot was offline
|
|
console.log('🔄 Reconciling invites for offline changes...');
|
|
let totalReconciled = 0;
|
|
for (const guildId of guildIds) {
|
|
try {
|
|
const guild = client.guilds.cache.get(guildId);
|
|
if (!guild) continue;
|
|
|
|
// Fetch current invites from Discord
|
|
const discordInvites = await guild.invites.fetch();
|
|
const currentInvites = Array.from(discordInvites.values());
|
|
|
|
// Reconcile with database
|
|
const reconciled = await api.reconcileInvites(guildId, currentInvites);
|
|
totalReconciled += reconciled;
|
|
} catch (e) {
|
|
console.error(`Failed to reconcile invites for guild ${guildId}:`, e && e.message ? e.message : e);
|
|
}
|
|
}
|
|
if (totalReconciled > 0) {
|
|
console.log(`✅ Invite reconciliation complete: removed ${totalReconciled} stale invites`);
|
|
} else {
|
|
console.log('✅ Invite reconciliation complete: no stale invites found');
|
|
}
|
|
|
|
const activities = [
|
|
{ name: 'Watch EhChad Live!', type: ActivityType.Streaming, url: 'https://twitch.tv/ehchad' },
|
|
{ name: 'Follow EhChad!', type: ActivityType.Streaming, url: 'https://twitch.tv/ehchad' },
|
|
{ name: '/help', type: ActivityType.Streaming, url: 'https://twitch.tv/ehchad' },
|
|
{ name: 'EhChadServices', type: ActivityType.Streaming, url: 'https://twitch.tv/ehchad' },
|
|
];
|
|
|
|
let activityIndex = 0;
|
|
|
|
setInterval(() => {
|
|
const activity = activities[activityIndex];
|
|
client.user.setActivity(activity.name, { type: activity.type, url: activity.url });
|
|
activityIndex = (activityIndex + 1) % activities.length;
|
|
}, 3000);
|
|
|
|
// Signal that startup is complete
|
|
console.log('✅ ECS - Full Stack Bot Online!');
|
|
},
|
|
};
|