diff --git a/packages/discord-bot/src/index.ts b/packages/discord-bot/src/index.ts index eb0a2c4..298c966 100644 --- a/packages/discord-bot/src/index.ts +++ b/packages/discord-bot/src/index.ts @@ -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; + 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, +}); diff --git a/packages/discord-bot/src/log.ts b/packages/discord-bot/src/log.ts new file mode 100644 index 0000000..d341777 --- /dev/null +++ b/packages/discord-bot/src/log.ts @@ -0,0 +1,5 @@ +export const log = (...args: unknown[]) => console.log(...args); + +export const error = (...args: unknown[]) => console.error(...args); + +export const warn = (...args: unknown[]) => console.warn(...args);