Skip to content

Commit 90c8b32

Browse files
authored
Fix IRC invite bug (#177)
1 parent f7a2865 commit 90c8b32

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/IRCBridge.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,22 @@ export class IRCBridge {
108108
return channel && channel.startsWith(this.config.channelPrefix);
109109
}
110110

111+
public async shouldInviteBot(roomId: string) {
112+
try {
113+
const currentMemberState = await this.mxClient.getRoomStateEvent(roomId, 'm.room.member', this.config.botUserId);
114+
return !['join','invite'].includes(currentMemberState.membership);
115+
} catch (ex) {
116+
// return ex instanceof MatrixError && ex.errcode === "M_NOT_FOUND";
117+
// MatrixError requires a newer version of the SDK (https://github.com/matrix-org/conference-bot/pull/163).
118+
// Assume the bot isn't in the room.
119+
return true;
120+
}
121+
}
122+
111123
public async plumbChannelToRoom(channel: string, roomId: string) {
112-
await this.mxClient.inviteUser(this.config.botUserId, roomId);
124+
if (await this.shouldInviteBot(roomId)) {
125+
await this.mxClient.inviteUser(this.config.botUserId, roomId);
126+
}
113127
await this.ircClient.join(channel);
114128
const result = await this.executeCommand(`plumb ${roomId} ${this.config.serverName} ${channel}`);
115129
const resultText = result.content.body;

0 commit comments

Comments
 (0)