matrix-appservice-discord: +2 patches

This commit is contained in:
chayleaf 2024-06-11 22:17:11 +07:00
parent 1a8c927f8b
commit 797ceec787
Signed by: chayleaf
GPG key ID: 78171AD46227E68E
3 changed files with 151 additions and 0 deletions

View file

@ -42,6 +42,29 @@ matrix-appservice-discord.overrideAttrs (old: {
hash = "sha256-1qb4Zah1XKzxTpVJqOOqz+TiXMFmnsIMZeuqJQdqSIA="; hash = "sha256-1qb4Zah1XKzxTpVJqOOqz+TiXMFmnsIMZeuqJQdqSIA=";
name = "bridge-matrix-edits-2.patch"; 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 ./disable-attachment-forwarding-to-matrix.patch
./reduce-spamminess.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,28 @@
diff --git a/src/config.ts b/src/config.ts
index 1e2f862..fd6e411 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -163,7 +163,7 @@ export class LoggingFile {
class DiscordBridgeConfigGhosts {
public nickPattern: string = ":nick";
- public usernamePattern: string = ":username#:tag";
+ public usernamePattern: string = ":username";
}
export class DiscordBridgeConfigMetrics {
diff --git a/src/usersyncroniser.ts b/src/usersyncroniser.ts
index b82722d..fb534c6 100644
--- a/src/usersyncroniser.ts
+++ b/src/usersyncroniser.ts
@@ -207,6 +207,10 @@ export class UserSyncroniser {
log.warn("Remote user wasn't found, using blank avatar");
}
const intent = this.bridge.getIntentForUserId(memberState.mxUserId);
+ const oldState = await intent.underlyingClient.getRoomStateEvent(roomId, "m.room.member", memberState.mxUserId);
+ if (oldState && (oldState.avatar_url || "") == avatar && (oldState.displayname || "") == memberState.displayName) {
+ return;
+ }
/* The intent class tries to be smart and deny a state update for <PL50 users.
Obviously a user can change their own state so we use the client instead. */
await intent.underlyingClient.sendStateEvent(roomId, "m.room.member", memberState.mxUserId, {