Fix service bots not rejecting invites on incoming DMs (#659)

* Manually send a reason on a leave for now

* changelog
This commit is contained in:
Will Hunt 2023-03-14 22:35:16 +00:00 committed by GitHub
parent 55529d7128
commit b8bb51fd1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

1
changelog.d/659.bugfix Normal file
View File

@ -0,0 +1 @@
Fix service bots not being able to reject invites with a reason.

View File

@ -791,18 +791,24 @@ export class Bridge {
// We got an invite but it's not a configured bot user, must be for a ghost user
log.debug(`Rejecting invite to room ${roomId} for ghost user ${invitedUserId}`);
const client = this.as.getIntentForUserId(invitedUserId).underlyingClient;
return client.kickUser(invitedUserId, roomId, "Bridge does not support DMing ghosts");
return client.doRequest("POST", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/leave", null, {
reason: "Bridge does not support DMing ghosts"
});
}
// Don't accept invites from people who can't do anything
if (!this.config.checkPermissionAny(event.sender, BridgePermissionLevel.login)) {
return botUser.intent.underlyingClient.kickUser(botUser.userId, roomId, "You do not have permission to invite this bot.");
return botUser.intent.underlyingClient.doRequest("POST", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/leave", null, {
reason: "You do not have permission to invite this bot."
});
}
if (event.content.is_direct && botUser.userId !== this.as.botUserId) {
// Service bots do not support direct messages (admin rooms)
log.debug(`Rejecting direct message (admin room) invite to room ${roomId} for service bot ${botUser.userId}`);
return botUser.intent.underlyingClient.kickUser(botUser.userId, roomId, "This bot does not support admin rooms.");
return botUser.intent.underlyingClient.doRequest("POST", "/_matrix/client/v3/rooms/" + encodeURIComponent(roomId) + "/leave", null, {
reason: "This bot does not support admin rooms."
});
}
// Accept the invite