|
|
@@ -4,10 +4,17 @@ import {addMessageEventsListener} from './events'; |
|
|
|
import {ForumChannel} from 'discord.js'; |
|
|
|
import {setupThreads} from './modules/thread'; |
|
|
|
import {BotContext} from './common'; |
|
|
|
import * as logger from './log'; |
|
|
|
|
|
|
|
const main = async () => { |
|
|
|
interface Params { |
|
|
|
logger?: Pick<typeof console, 'log' | 'error' | 'warn'>; |
|
|
|
config: typeof config; |
|
|
|
} |
|
|
|
|
|
|
|
const main = async (params = {} as Params) => { |
|
|
|
const { logger: l = logger, config: c, } = params |
|
|
|
const client = createClient({ |
|
|
|
intents: config.meta.intentsInteger, |
|
|
|
intents: c.meta.intentsInteger, |
|
|
|
}); |
|
|
|
|
|
|
|
const context: BotContext = { |
|
|
@@ -23,25 +30,31 @@ const main = async () => { |
|
|
|
|
|
|
|
client.on('ready', async () => { |
|
|
|
if (!client.user) { |
|
|
|
console.error('Not logged in!'); |
|
|
|
l.error('Not logged in!'); |
|
|
|
return; |
|
|
|
} |
|
|
|
console.log(`Logged in as ${client.user.tag}`); |
|
|
|
l.log(`Logged in as ${client.user.tag}!`); |
|
|
|
|
|
|
|
const channel = await client.channels.fetch(config.meta.channelId); |
|
|
|
const channel = await client.channels.fetch(c.meta.channelId); |
|
|
|
if (!(channel instanceof ForumChannel)) { |
|
|
|
console.error(`Channel ${config.meta.channelId} is not a forum!`); |
|
|
|
l.error(`Channel ${c.meta.channelId} is not a forum!`); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
context.channel = channel; |
|
|
|
l.log('Syncing up threads...'); |
|
|
|
await setupThreads(context); |
|
|
|
l.log('Sync done! Now listening for new messages.'); |
|
|
|
}); |
|
|
|
|
|
|
|
addMessageEventsListener(context); |
|
|
|
await client.login(config.meta.token); |
|
|
|
l.log('Logging in to gateway...'); |
|
|
|
await client.login(c.meta.token); |
|
|
|
} |
|
|
|
|
|
|
|
// TODO load channelId from config |
|
|
|
// TODO add discord wizard for chatting with bot for setup (e.g. selecting forum channel ID) |
|
|
|
void main(); |
|
|
|
void main({ |
|
|
|
logger, |
|
|
|
config, |
|
|
|
}); |