File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -108,8 +108,22 @@ export class IRCBridge {
108
108
return channel && channel . startsWith ( this . config . channelPrefix ) ;
109
109
}
110
110
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
+
111
123
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
+ }
113
127
await this . ircClient . join ( channel ) ;
114
128
const result = await this . executeCommand ( `plumb ${ roomId } ${ this . config . serverName } ${ channel } ` ) ;
115
129
const resultText = result . content . body ;
You can’t perform that action at this time.
0 commit comments