matrix-appservice-discord: +1 patch

This commit is contained in:
chayleaf 2024-06-11 22:17:11 +07:00
parent 7aacb1449a
commit 79154f71b1
Signed by: chayleaf
GPG key ID: 78171AD46227E68E
5 changed files with 179 additions and 7 deletions

View file

@ -95,16 +95,18 @@
# extended lib
lib = nixpkgs.lib // import ./lib.nix { inherit (nixpkgs) lib; };
# can't use callPackage ./pkgs here, idk why; use import instead
overlay' = args: self: super: import ./pkgs ({
overlay' = args: self: super: import (if args.pluginsOverlay or false then ./pkgs/nix-plugins-overlay.nix else ./pkgs) ({
pkgs = super;
pkgs' = self;
lib = super.lib;
inherit inputs;
} // args);
overlay = overlay' { };
nix-plugins-overlay = overlay' { pluginsOverlay = true; };
all-overlays = [ nix-plugins-overlay overlay ];
# I override some settings down the line, but overlays always stay the same
mkPkgs = config: import nixpkgs (config // {
overlays = config.overlays or [ ] ++ [ overlay ];
overlays = config.overlays or [ ] ++ all-overlays;
});
# this is actual config, it gets processed below
config = let
@ -151,7 +153,10 @@
};
in {
overlays.default = overlay;
overlays = {
default = overlay;
nix-plugins = nix-plugins-overlay;
};
packages = lib.genAttrs [
"x86_64-linux"
"aarch64-linux"
@ -194,7 +199,7 @@
}; }
(getPrivSys hostname)
{ networking.hostName = lib.mkDefault hostname;
nixpkgs.overlays = [ overlay ]; }
nixpkgs.overlays = all-overlays; }
inputs.impermanence.nixosModule
]
++ args.modules or [ ]
@ -211,7 +216,7 @@
{ nixpkgs = home.common.nixpkgs or { };
nix = home.common.nix or { }; }
({ config, pkgs, lib, ...}: {
nixpkgs.overlays = [ overlay ];
nixpkgs.overlays = all-overlays;
nix.package = lib.mkDefault pkgs.nixForNixPlugins; })
(getPrivUser hostname username)
];
@ -240,7 +245,7 @@
++ [
(getPrivUser hostname user)
({ pkgs, lib, ... }: {
nixpkgs.overlays = [ overlay ];
nixpkgs.overlays = all-overlays;
nix.package = lib.mkDefault pkgs.nixForNixPlugins;
})
];

View file

@ -11,7 +11,6 @@ let
sources = import ./_sources/generated.nix {
inherit (pkgs) fetchgit fetchurl fetchFromGitHub dockerTools;
};
nixForNixPlugins = pkgs.nixVersions.nix_2_18;
nur = import inputs.nur {
inherit pkgs;
nurpkgs = pkgs;

View file

@ -42,6 +42,28 @@ matrix-appservice-discord.overrideAttrs (old: {
hash = "sha256-1qb4Zah1XKzxTpVJqOOqz+TiXMFmnsIMZeuqJQdqSIA=";
name = "bridge-matrix-edits-2.patch";
})
# https://github.com/matrix-org/matrix-appservice-discord/pull/862
(fetchpatch {
url = "https://github.com/matrix-org/matrix-appservice-discord/commit/3106957ebd857bc88ba3f62182a61dd00275f2fc.patch";
hash = "sha256-Xf+TuWXNVqi+0YRwBbCkLcMfsYNxq1ZlsgLWpwjqPww=";
name = "discord-to-matrix-reactions-1.patch";
})
(fetchpatch {
url = "https://github.com/matrix-org/matrix-appservice-discord/commit/a8186874b03c545a8728892b299a4367776fc538.patch";
hash = "sha256-Hq2HY44hPeGPXI3MglyN7Am+NCNAHAbr2hYhXvDYtGk=";
name = "discord-to-matrix-reactions-2.patch";
})
(fetchpatch {
url = "https://github.com/matrix-org/matrix-appservice-discord/commit/da2c3b88c7dd4f3a679890c58f934e9b2ed775df.patch";
hash = "sha256-4NMAr+Ni+7pI/I007YH5Y+4ZwAhwg91/BXGvLVcO0BQ=";
name = "discord-to-matrix-reactions-3.patch";
})
(fetchpatch {
url = "https://github.com/matrix-org/matrix-appservice-discord/commit/a33f269c88c432c532d7816f180e5262d73ebf02.patch";
hash = "sha256-0WkfDkQsDoxfKH3MgPb893UPDPxeWueQwVSaxD2RKAw=";
name = "discord-to-matrix-reactions-4.patch";
})
./reactions-as-mxc-urls.patch
./disable-attachment-forwarding-to-matrix.patch
];
})

View file

@ -0,0 +1,100 @@
diff --git a/src/bot.ts b/src/bot.ts
index 4445aa6..8613b5a 100644
--- a/src/bot.ts
+++ b/src/bot.ts
@@ -1199,7 +1199,9 @@ export class DiscordBot {
public async OnMessageReactionAdd(reaction: Discord.MessageReaction, user: Discord.User | Discord.PartialUser) {
const message = reaction.message;
- const reactionName = reaction.emoji.name;
+ const reactionName = (reaction.emoji.id
+ ? await this.GetEmoji(reaction.emoji.name, reaction.emoji.animated, reaction.emoji.id) + "#" + reaction.emoji.name
+ : reaction.emoji.name);
log.verbose(`Got message reaction add event for ${message.id} with ${reactionName}`);
const storeEvent = await this.store.Get(DbEvent, {
@@ -1229,7 +1231,7 @@ export class DiscordBot {
const reactionEventId = await intent.underlyingClient.unstableApis.addReactionToEvent(
roomId,
eventId,
- reaction.emoji.id ? `:${reactionName}:` : reactionName
+ reactionName,
);
const event = new DbEvent();
@@ -1246,7 +1248,10 @@ export class DiscordBot {
public async OnMessageReactionRemove(reaction: Discord.MessageReaction, user: Discord.User | Discord.PartialUser) {
const message = reaction.message;
- log.verbose(`Got message reaction remove event for ${message.id} with ${reaction.emoji.name}`);
+ const reactionName = (reaction.emoji.id
+ ? await this.GetEmoji(reaction.emoji.name, reaction.emoji.animated, reaction.emoji.id) + "#" + reaction.emoji.name
+ : reaction.emoji.name);
+ log.verbose(`Got message reaction remove event for ${message.id} with ${reactionName}`);
const storeEvent = await this.store.Get(DbEvent, {
discord_id: message.id,
@@ -1274,7 +1279,7 @@ export class DiscordBot {
const underlyingClient = intent.underlyingClient;
- const { chunk } = await underlyingClient.unstableApis.getRelationsForEvent(
+ const { chunk } = await underlyingClient.getRelationsForEvent(
roomId,
eventId,
"m.annotation"
@@ -1285,7 +1290,7 @@ export class DiscordBot {
return false;
}
- return event.content["m.relates_to"].key === reaction.emoji.name;
+ return event.content["m.relates_to"].key === reactionName;
});
if (!event) {
@@ -1324,7 +1329,7 @@ export class DiscordBot {
const [ eventId, roomId ] = storeEvent.MatrixId.split(";");
const underlyingClient = this.bridge.botIntent.underlyingClient;
- const { chunk } = await underlyingClient.unstableApis.getRelationsForEvent(
+ const { chunk } = await underlyingClient.getRelationsForEvent(
roomId,
eventId,
"m.annotation"
diff --git a/test/mocks/appservicemock.ts b/test/mocks/appservicemock.ts
index 06cc3ce..f6ef585 100644
--- a/test/mocks/appservicemock.ts
+++ b/test/mocks/appservicemock.ts
@@ -281,6 +281,10 @@ class MatrixClientMock extends AppserviceMockBase {
public async redactEvent(roomId: string, eventId: string, reason?: string | null) {
this.funcCalled("redactEvent", roomId, eventId, reason);
}
+
+ public async getRelationsForEvent(roomId: string, eventId: string, relationType?: string, eventType?: string): Promise<any> {
+ this.funcCalled("getRelationsForEvent", roomId, eventId, relationType, eventType);
+ }
}
class UnstableApis extends AppserviceMockBase {
@@ -288,8 +292,4 @@ class UnstableApis extends AppserviceMockBase {
public async addReactionToEvent(roomId: string, eventId: string, emoji: string) {
this.funcCalled("addReactionToEvent", roomId, eventId, emoji);
}
-
- public async getRelationsForEvent(roomId: string, eventId: string, relationType?: string, eventType?: string): Promise<any> {
- this.funcCalled("getRelationsForEvent", roomId, eventId, relationType, eventType);
- }
}
diff --git a/test/test_discordbot.ts b/test/test_discordbot.ts
index 9c9e469..2109bb7 100644
--- a/test/test_discordbot.ts
+++ b/test/test_discordbot.ts
@@ -501,7 +501,7 @@ describe("DiscordBot", () => {
discordBot = getDiscordBot();
const intent = mockBridge.getIntent(author.id);
- intent.underlyingClient.unstableApis.getRelationsForEvent = async () => {
+ intent.underlyingClient.getRelationsForEvent = async () => {
return {
chunk: [
{

View file

@ -0,0 +1,46 @@
{ pkgs, pkgs', ... }:
let
nixForNixPlugins = pkgs.nixVersions.nix_2_18;
in {
inherit nixForNixPlugins;
nix = nixForNixPlugins;
nixVersions = pkgs.nixVersions // {
stable = nixForNixPlugins;
unstable = nixForNixPlugins;
};
# Various patches to change Nix version of existing packages so they don't error out because of nix-plugins in nix.conf
/*nix-plugins = (pkgs.nix-plugins.override { nix = nixForNixPlugins; }).overrideAttrs (old: {
version = "13.0.0";
patches = [
(pkgs.fetchpatch {
# pull 16
url = "https://github.com/chayleaf/nix-plugins/commit/8f945cadad7f2e60e8f308b2f498ec5e16961ede.patch";
hash = "sha256-pOogMtjXYkSDtXW12TmBpGr/plnizJtud2nP3q2UldQ=";
})
];
});*/
harmonia = (pkgs.harmonia.override { nixVersions.nix_2_21 = nixForNixPlugins; }).overrideAttrs (old: rec {
version = "0.7.3";
src = old.src.override {
rev = "refs/tags/${old.pname}-v${version}";
hash = "sha256-XtnK54HvZMKZGSCrVD0FO5PQLMo3Vkj8ezUlsfqStq0=";
};
cargoDeps = pkgs'.rustPlatform.importCargoLock { lockFile = "${src}/Cargo.lock"; };
});
nix-init = pkgs.nix-init.override { nix = nixForNixPlugins; };
nix-serve = pkgs.nix-serve.override { nix = nixForNixPlugins; };
nix-serve-ng = pkgs.nix-serve-ng.override { nix = nixForNixPlugins; };
hydra_unstable = (pkgs.hydra_unstable.override {
nix = nixForNixPlugins;
}).overrideAttrs (old: {
version = "2023-12-01";
# who cares about tests amirite
doCheck = false;
src = old.src.override {
rev = "4d1c8505120961f10897b8fe9a070d4e193c9a13";
hash = "sha256-vXTuE83GL15mgZHegbllVAsVdDFcWWSayPfZxTJN5ys=";
};
});
nurl = pkgs.nurl.override { nix = nixForNixPlugins; };
}