diff --git a/machines/servo/services/matrix/default.nix b/machines/servo/services/matrix/default.nix index 3f786f16..9baece2a 100644 --- a/machines/servo/services/matrix/default.nix +++ b/machines/servo/services/matrix/default.nix @@ -88,9 +88,17 @@ homeserverUrl = "http://127.0.0.1:8008"; domain = "uninsane.org"; adminMxid = "admin.matrix@uninsane.org"; + # self-service bridging is when a Matrix user bridges by DMing @_discord_bot: + # i don't know what the alternative is :? enableSelfServiceBridging = true; + presenceInterval = 30000; # milliseconds + # allows matrix users to search for Discord channels (somehow?) disablePortalBridging = false; - disableInviteNotifications = false; + # disableReadReceipts = true; + # these are Matrix -> Discord + disableJoinLeaveNotifications = true; + disableInviteNotifications = true; + disableRoomTopicNotifications = true; }; # these are marked as required in the yaml schema auth = { diff --git a/pkgs/matrix-appservice-discord/03-no-edits.patch b/pkgs/matrix-appservice-discord/03-no-edits.patch new file mode 100644 index 00000000..6ccd9dca --- /dev/null +++ b/pkgs/matrix-appservice-discord/03-no-edits.patch @@ -0,0 +1,14 @@ +diff --git a/src/bot.ts b/src/bot.ts +index 8bc73d4..1e6ea67 100644 +--- a/src/bot.ts ++++ b/src/bot.ts +@@ -568,7 +568,8 @@ export class DiscordBot { + } + const link = `https://discord.com/channels/${chan.guild.id}/${chan.id}/${editEventId}`; + embedSet.messageEmbed.description = `[Edit](${link}): ${embedSet.messageEmbed.description}`; +- await this.send(embedSet, opts, roomLookup, event); ++ log.warn("not editing sent Matrix -> Discord message"); ++ // await this.send(embedSet, opts, roomLookup, event); + } catch (err) { + // throw wrapError(err, Unstable.ForeignNetworkError, "Couldn't edit message"); + log.warn(`Failed to edit message ${event.event_id}`); diff --git a/pkgs/matrix-appservice-discord/04-no-kickbans.patch b/pkgs/matrix-appservice-discord/04-no-kickbans.patch new file mode 100644 index 00000000..d2a5581e --- /dev/null +++ b/pkgs/matrix-appservice-discord/04-no-kickbans.patch @@ -0,0 +1,88 @@ +diff --git a/src/bot.ts b/src/bot.ts +index 8bc73d4..1e6ea67 100644 +--- a/src/bot.ts ++++ b/src/bot.ts +@@ -795,82 +796,7 @@ export class DiscordBot { + roomId: string, kickeeUserId: string, kicker: string, kickban: "leave"|"ban", + previousState: string, reason?: string, + ) { +- const restore = kickban === "leave" && previousState === "ban"; +- const client = await this.clientFactory.getClient(kicker); +- let channel: Discord.Channel; +- try { +- channel = await this.GetChannelFromRoomId(roomId, client); +- } catch (ex) { +- log.error("Failed to get channel for ", roomId, ex); +- return; +- } +- if (channel.type !== "text") { +- log.warn("Channel was not a text channel"); +- return; +- } +- const tchan = (channel as Discord.TextChannel); +- const kickeeUser = await this.GetDiscordUserOrMember( +- kickeeUserId.substring("@_discord_".length, kickeeUserId.indexOf(":") - 1), +- tchan.guild.id, +- ); +- if (!kickeeUser) { +- log.error("Could not find discord user for", kickeeUserId); +- return; +- } +- const kickee = kickeeUser as Discord.GuildMember; +- let res: Discord.Message; +- const botChannel = await this.GetChannelFromRoomId(roomId) as Discord.TextChannel; +- if (restore) { +- await tchan.overwritePermissions([ +- { +- allow: ["SEND_MESSAGES", "VIEW_CHANNEL"], +- id: kickee.id, +- }], +- `Unbanned.`, +- ); +- this.channelLock.set(botChannel.id); +- res = await botChannel.send( +- `${kickee} was unbanned from this channel by ${kicker}.`, +- ) as Discord.Message; +- this.sentMessages.push(res.id); +- this.channelLock.release(botChannel.id); +- return; +- } +- const existingPerms = tchan.permissionsFor(kickee); +- if (existingPerms && existingPerms.has(Discord.Permissions.FLAGS.VIEW_CHANNEL as number) === false ) { +- log.warn("User isn't allowed to read anyway."); +- return; +- } +- const word = `${kickban === "ban" ? "banned" : "kicked"}`; +- this.channelLock.set(botChannel.id); +- res = await botChannel.send( +- `${kickee} was ${word} from this channel by ${kicker}.` +- + (reason ? ` Reason: ${reason}` : ""), +- ) as Discord.Message; +- this.sentMessages.push(res.id); +- this.channelLock.release(botChannel.id); +- log.info(`${word} ${kickee}`); +- +- await tchan.overwritePermissions([ +- { +- deny: ["SEND_MESSAGES", "VIEW_CHANNEL"], +- id: kickee.id, +- }], +- `Matrix user was ${word} by ${kicker}.`, +- ); +- if (kickban === "leave") { +- // Kicks will let the user back in after ~30 seconds. +- setTimeout(async () => { +- log.info(`Kick was lifted for ${kickee.displayName}`); +- await tchan.overwritePermissions([ +- { +- allow: ["SEND_MESSAGES", "VIEW_CHANNEL"], +- id: kickee.id, +- }], +- `Lifting kick since duration expired.`, +- ); +- }, this.config.room.kickFor); +- } ++ return; // this is about letting Discord users know when Matrix users are kicked/banned + } + + public async GetEmojiByMxc(mxc: string): Promise { diff --git a/pkgs/matrix-appservice-discord/05-no-meta.patch b/pkgs/matrix-appservice-discord/05-no-meta.patch new file mode 100644 index 00000000..f8032f5f --- /dev/null +++ b/pkgs/matrix-appservice-discord/05-no-meta.patch @@ -0,0 +1,13 @@ +diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts +index f1f4611..7b57ff3 100644 +--- a/src/matrixeventprocessor.ts ++++ b/src/matrixeventprocessor.ts +@@ -278,6 +278,8 @@ export class MatrixEventProcessor { + return; + } + ++ return; // disable all meta notifications ++ + msg += " on Matrix."; + const channel = await this.discord.GetChannelFromRoomId(event.room_id) as Discord.TextChannel; + await this.discord.sendAsBot(msg, channel, event); diff --git a/pkgs/matrix-appservice-discord/default.nix b/pkgs/matrix-appservice-discord/default.nix index 5b093b60..3fe34713 100644 --- a/pkgs/matrix-appservice-discord/default.nix +++ b/pkgs/matrix-appservice-discord/default.nix @@ -8,6 +8,12 @@ ./01-puppet.patch # don't ask Discord admin for approval before bridging ./02-auto-approve.patch + # disable Matrix -> Discord edits because they do not fit Discord semantics + ./03-no-edits.patch + # we don't want to notify Discord users that a Matrix user was kicked/banned + ./04-no-kickbans.patch + # don't notify Discord users when the Matrix room changes (name, topic, membership) + ./05-no-meta.patch ]; }))