From e8883e992b2943714c9036b9dddb17cab49dbbd2 Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Sat, 4 Feb 2023 08:50:36 +0000 Subject: [PATCH 1/7] Use auditorium slugs in IRC channel names --- src/IRCBridge.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IRCBridge.ts b/src/IRCBridge.ts index dc02055..7aa9e0a 100644 --- a/src/IRCBridge.ts +++ b/src/IRCBridge.ts @@ -62,7 +62,7 @@ export class IRCBridge { } public async deriveChannelName(auditorium: Auditorium) { - const name = await auditorium.getName(); + const name = await auditorium.getSlug(); if (!name) { throw Error('Auditorium name is empty'); } From e4988fce53c96f734abe961c3dfe99be16a7ece5 Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Sat, 4 Feb 2023 08:50:53 +0000 Subject: [PATCH 2/7] Fix plumbAll calling plumbOne incorrectly --- src/commands/IrcPlumbCommand.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/IrcPlumbCommand.ts b/src/commands/IrcPlumbCommand.ts index 322459e..2f8a4f8 100644 --- a/src/commands/IrcPlumbCommand.ts +++ b/src/commands/IrcPlumbCommand.ts @@ -34,7 +34,7 @@ export class IrcPlumbCommand implements ICommand { for (const auditorium of this.conference.storedAuditoriums) { const channelName = await this.ircBridge.deriveChannelName(auditorium); try { - await this.plumbOne(this.client, channelName, auditorium.roomId); + await this.plumbOne(this.client, auditorium.roomId, channelName); // Wait before plumbing the next one so as to not overwhelm the poor bridge. await new Promise(r => setTimeout(r, PLUMB_WAIT_MS)); } catch (ex) { @@ -45,7 +45,7 @@ export class IrcPlumbCommand implements ICommand { for (const interest of this.conference.storedInterestRooms) { const channelName = await this.ircBridge.deriveChannelNameSI(interest); try { - await this.plumbOne(this.client, channelName, interest.roomId); + await this.plumbOne(this.client, interest.roomId, channelName); // Wait before plumbing the next one so as to not overwhelm the poor bridge. await new Promise(r => setTimeout(r, PLUMB_WAIT_MS)); } catch (ex) { From 9cd4a93b376e74c3b2aaf1316d20b9f9cddc491c Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Sat, 4 Feb 2023 09:32:19 +0000 Subject: [PATCH 3/7] Increase wait time for plumb command --- src/commands/IrcPlumbCommand.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/IrcPlumbCommand.ts b/src/commands/IrcPlumbCommand.ts index 2f8a4f8..863f005 100644 --- a/src/commands/IrcPlumbCommand.ts +++ b/src/commands/IrcPlumbCommand.ts @@ -22,7 +22,7 @@ import { logMessage } from "../LogProxy"; import { KickPowerLevel } from "../models/room_kinds"; import { ConferenceMatrixClient } from "../ConferenceMatrixClient"; -const PLUMB_WAIT_MS = 1000; +const PLUMB_WAIT_MS = 10000; export class IrcPlumbCommand implements ICommand { public readonly prefixes = ["plumb-irc"]; From 97290d72c3a84c1fc3e907689f9cf03f5415e08c Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Sat, 4 Feb 2023 09:32:27 +0000 Subject: [PATCH 4/7] Only run PL update if needed --- src/commands/IrcPlumbCommand.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/commands/IrcPlumbCommand.ts b/src/commands/IrcPlumbCommand.ts index 863f005..5acab81 100644 --- a/src/commands/IrcPlumbCommand.ts +++ b/src/commands/IrcPlumbCommand.ts @@ -15,7 +15,7 @@ limitations under the License. */ import { ICommand } from "./ICommand"; -import { LogLevel, LogService, MatrixClient } from "matrix-bot-sdk"; +import { LogLevel, LogService, MatrixClient, PowerLevelAction } from "matrix-bot-sdk"; import { Conference } from "../Conference"; import { IRCBridge } from "../IRCBridge"; import { logMessage } from "../LogProxy"; @@ -71,8 +71,10 @@ export class IrcPlumbCommand implements ICommand { } try { - // The bridge needs the ability to kick KLINED users. - await client.setUserPowerLevel(this.ircBridge.botUserId, resolvedRoomId, KickPowerLevel); + if (!await client.userHasPowerLevelForAction(this.ircBridge.botUserId, resolvedRoomId, PowerLevelAction.Kick)) { + // The bridge needs the ability to kick KLINED users. + await client.setUserPowerLevel(this.ircBridge.botUserId, resolvedRoomId, KickPowerLevel); + } } catch (ex) { LogService.warn("IrcPlumbCommand", ex); return logMessage(LogLevel.WARN, "IrcPlumbCommand", `Could not plumb channel to room ${resolvedRoomId}: could not set AS power level`, this.client); From 450630dfa37ed852e500ee351957ae3bb34f5e71 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Sat, 4 Feb 2023 09:33:07 +0000 Subject: [PATCH 5/7] Don't log an error on already existing --- src/IRCBridge.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/IRCBridge.ts b/src/IRCBridge.ts index 7aa9e0a..a0000fc 100644 --- a/src/IRCBridge.ts +++ b/src/IRCBridge.ts @@ -134,6 +134,10 @@ export class IRCBridge { await this.ircClient.join(channel); const result = await this.executeCommand(`plumb ${roomId} ${this.config.serverName} ${channel}`); const resultText = result.content.body; + if (resultText.match(/Room mapping already exists/)) { + // Already bridged + return; + } if (resultText !== 'Room plumbed.') { throw Error(`IRC bridge gave an error: ${resultText}`); } From 72b2747e7de700e50c9ecd06467a1d56271fd18e Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Sat, 4 Feb 2023 09:34:31 +0000 Subject: [PATCH 6/7] Add try catch around bridge version --- src/IRCBridge.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/IRCBridge.ts b/src/IRCBridge.ts index a0000fc..439c2dc 100644 --- a/src/IRCBridge.ts +++ b/src/IRCBridge.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {LogService, MatrixClient, MatrixEvent} from "matrix-bot-sdk"; +import { LogService, MatrixClient, MatrixEvent } from "matrix-bot-sdk"; import * as irc from "irc-upd"; import { Auditorium } from "./models/Auditorium"; import { InterestRoom } from "./models/InterestRoom"; @@ -93,9 +93,13 @@ export class IRCBridge { } else { this.botRoomId = data.roomId; } - - // This should timeout if the connection is broken - await this.executeCommand("bridgeversion"); + + try { + // This should timeout if the connection is broken + await this.executeCommand("bridgeversion"); + } catch (ex) { + LogService.warn(`IRCBridge`, "Failed to get IRC bridge version, it may be unreachable."); + } this.ircClient = new irc.Client(this.config.serverName, this.config.botNick, { port: this.config.port, From b4ae9a2666057f641d1fbfa429115b952cb07add Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Sat, 4 Feb 2023 10:13:48 +0000 Subject: [PATCH 7/7] fix PL action --- src/commands/IrcPlumbCommand.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/commands/IrcPlumbCommand.ts b/src/commands/IrcPlumbCommand.ts index 5acab81..9fcf80e 100644 --- a/src/commands/IrcPlumbCommand.ts +++ b/src/commands/IrcPlumbCommand.ts @@ -15,12 +15,13 @@ limitations under the License. */ import { ICommand } from "./ICommand"; -import { LogLevel, LogService, MatrixClient, PowerLevelAction } from "matrix-bot-sdk"; +import { LogLevel, LogService, MatrixClient } from "matrix-bot-sdk"; import { Conference } from "../Conference"; import { IRCBridge } from "../IRCBridge"; import { logMessage } from "../LogProxy"; import { KickPowerLevel } from "../models/room_kinds"; import { ConferenceMatrixClient } from "../ConferenceMatrixClient"; +import { PowerLevelAction } from "matrix-bot-sdk/lib/models/PowerLevelAction"; const PLUMB_WAIT_MS = 10000;