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

Speed up load times and improve logging on join events #42

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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