Skip to content
Extraits de code Groupes Projets

Fix matrix reply on modified message for discord

@@ -324,6 +324,54 @@ export class MatrixEventProcessor {
};
}
public async ReplyEventToEmbed(
event: IMatrixEvent, repliedEvent: IMatrixEvent, channel: Discord.TextChannel, getReply: boolean = true,
): Promise<IMatrixEventProcessorResult> {
const mxClient = this.bridge.botIntent.underlyingClient;
const profile = await this.GetUserProfileForRoom(repliedEvent.room_id, repliedEvent.sender);
const params = {
mxClient,
roomId: repliedEvent.room_id,
userId: repliedEvent.sender,
} as IMatrixMessageProcessorParams;
if (profile) {
params.displayname = profile.displayname;
}
let formattedBodyRegex = new RegExp("<br(?: \/)?>(.*)<\/blockquote>",'g');
let bodyRegex = new RegExp("> <@[^\.>]*:[^\.>]*\.[^\.>]*> (.*)",'g');
let body: string = "";
if (event.type !== "m.sticker") {
const replyContent = repliedEvent.content;
const baseContent = event.content;
if(replyContent && baseContent && replyContent["body"] && baseContent["body"]){
replyContent["body"] = [...baseContent["body"].matchAll(bodyRegex)][0][1]
}
if(replyContent && baseContent && replyContent["formatted_body"] && baseContent["formatted_body"]){
replyContent["formatted_body"] = [...baseContent["formatted_body"].matchAll(formattedBodyRegex)][0][1]
}
body = await this.matrixMsgProcessor.FormatMessage(replyContent as IMatrixMessage, channel.guild, params);
}
const messageEmbed = new Discord.MessageEmbed();
messageEmbed.setDescription(body);
await this.SetEmbedAuthor(messageEmbed, repliedEvent.sender, profile);
const replyEmbed = getReply ? (await this.GetEmbedForReply(repliedEvent, channel)) : undefined;
if (replyEmbed && replyEmbed.fields) {
for (let i = 0; i < replyEmbed.fields.length; i++) {
const f = replyEmbed.fields[i];
if (f.name === "ping") {
messageEmbed.description += `\n(${f.value})`;
replyEmbed.fields.splice(i, 1);
break;
}
}
}
return {
messageEmbed,
replyEmbed,
};
}
public async HandleAttachment(
event: IMatrixEvent,
mxClient: MatrixClient,
@@ -391,7 +439,7 @@ export class MatrixEventProcessor {
if (!sourceEvent || !sourceEvent.content || !sourceEvent.content.body) {
throw Error("No content could be found");
}
const replyEmbed = (await this.EventToEmbed(sourceEvent, channel, true)).messageEmbed;
const replyEmbed = (await this.ReplyEventToEmbed(event, sourceEvent, channel, true)).messageEmbed;
// if we reply to a discord member, ping them!
if (this.bridge.isNamespacedUser(sourceEvent.sender)) {
Chargement en cours