From 710c747acd71fdc8b04391398e8e33b0a804c4e1 Mon Sep 17 00:00:00 2001 From: aronson Date: Tue, 10 Oct 2023 01:14:17 -0500 Subject: [PATCH] Speed up load times and improve logging on join events (#42) * Speed up loading time * Further improve logging --- lib/bot.ts | 11 ++++++++--- lib/ircListeners.ts | 7 ++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/bot.ts b/lib/bot.ts index 4162008..aaaea29 100644 --- a/lib/bot.ts +++ b/lib/bot.ts @@ -145,16 +145,21 @@ export default class Bot { async connect() { this.debug && this.logger.debug('Connecting to IRC and Discord'); + this.attachDiscordListeners(); + this.attachIrcListeners(); + + // Begin connection to remote servers + const ircPromise = this.ircClient.connect(this.config.server, this.config.port, this.config.tls); await this.discord.connect(); // Extract id and token from Webhook urls and connect. this.channelMapping = await ChannelMapper.CreateAsync(this.config, this, this.discord); - this.attachIrcListeners(); - await this.ircClient.connect(this.config.server, this.config.port, this.config.tls); + // Join IRC channels + await ircPromise; this.channelMapping.ircNameToMapping.forEach((entry) => { - this.logger.info(`Joining channel ${entry.ircChannel}`); + this.logger.info(`Joining IRC channel ${entry.ircChannel}`); this.ircClient.join(entry.ircChannel); }); } diff --git a/lib/ircListeners.ts b/lib/ircListeners.ts index 2ddf1a7..e8041b2 100644 --- a/lib/ircListeners.ts +++ b/lib/ircListeners.ts @@ -106,7 +106,11 @@ export function createIrcJoinListener(bot: Bot) { return async (event: JoinEvent) => { const channelName = event.params.channel; const nick = event.source?.name ?? ''; - bot.debug && bot.logger.debug(`Received join: ${channelName} -- ${nick}`); + if (nick === bot.config.ircOptions?.nick ?? bot.config.nickname) { + bot.logger.done(`Joined IRC channel ${channelName}`); + } else { + bot.debug && bot.logger.debug(`Received join: ${channelName} -- ${nick}`); + } const channel = channelName.toLowerCase(); if (nick === bot.config.nickname && !bot.config.announceSelfJoin) { return; @@ -114,6 +118,7 @@ export function createIrcJoinListener(bot: Bot) { // self-join is announced before names (which includes own nick) // so don't add nick to channelUsers if ( + nick !== bot.config.ircOptions?.nick && nick !== bot.config.nickname && bot.channelUsers[channel].indexOf(nick) === -1 ) {