Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Speed up load times and improve logging on join events (#42)
Browse files Browse the repository at this point in the history
* Speed up loading time

* Further improve logging
  • Loading branch information
aronson committed Oct 10, 2023
1 parent a03acd2 commit 710c747
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 8 additions & 3 deletions lib/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
7 changes: 6 additions & 1 deletion lib/ircListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,19 @@ 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;
}
// 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
) {
Expand Down

0 comments on commit 710c747

Please sign in to comment.