-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathready.ts
More file actions
56 lines (51 loc) · 1.97 KB
/
Copy pathready.ts
File metadata and controls
56 lines (51 loc) · 1.97 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
import { Events } from 'discord.js';
import { config } from '../env.js';
import { initializeAdventScheduler } from '../util/advent-scheduler.js';
import { fetchAndCachePublicChannelsMessages } from '../util/cache.js';
import { createEvent } from '../util/events.js';
import { syncGuidesToChannel } from '../util/post-guides.js';
import { leaveIfNotAllowedServer } from '../util/server-guard.js';
export const readyEvent = createEvent(
{
name: Events.ClientReady,
once: true,
},
async (client) => {
console.log(`Ready! Logged in as ${client.user.tag}`);
// Check all guilds and leave any unauthorized ones
console.log(`🔍 Checking ${client.guilds.cache.size} guild(s)...`);
for (const guild of client.guilds.cache.values()) {
await leaveIfNotAllowedServer(guild);
}
if (config.fetchAndSyncMessages) {
const guild = client.guilds.cache.get(config.serverId);
if (guild) {
await fetchAndCachePublicChannelsMessages(guild, true);
}
// Sync guides to channel
try {
console.log(`🔄 Starting guide sync to channel ${config.channelIds.guides}...`);
await syncGuidesToChannel(client, config.channelIds.guides);
} catch (error) {
if (error && typeof error === 'object' && 'code' in error) {
const discordError = error as { code: number; message?: string };
if (discordError.code === 50001) {
console.warn(
'⚠️ Bot does not have access to the guides channel. Please check bot permissions and channel ID.'
);
} else {
console.error('❌ Failed to sync guides:', error);
}
} else {
console.error('❌ Failed to sync guides:', error);
}
}
}
// Initialize Advent of Code scheduler
try {
initializeAdventScheduler(client, config.channelIds.adventOfCode);
} catch (error) {
console.error('❌ Failed to initialize Advent of Code scheduler:', error);
}
}
);