Skip to content
Extraits de code Groupes Projets
Valider 019e0e9c rédigé par Deurstann's avatar Deurstann
Parcourir les fichiers

Fix matrix reply on modified message for discord

parent 2fd24ef3
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -324,6 +324,54 @@ export class MatrixEventProcessor { ...@@ -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>")
let bodyRegex = new RegExp("> <@[^\.>]*:[^\.>]*\.[^\.>]*> (.*)");
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]
}
if(replyContent && baseContent && replyContent["formatted_body"] && baseContent["formatted_body"]){
replyContent["formatted_body"] = baseContent["formatted_body"].matchAll(formattedBodyRegex)[0]
}
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( public async HandleAttachment(
event: IMatrixEvent, event: IMatrixEvent,
mxClient: MatrixClient, mxClient: MatrixClient,
...@@ -391,7 +439,7 @@ export class MatrixEventProcessor { ...@@ -391,7 +439,7 @@ export class MatrixEventProcessor {
if (!sourceEvent || !sourceEvent.content || !sourceEvent.content.body) { if (!sourceEvent || !sourceEvent.content || !sourceEvent.content.body) {
throw Error("No content could be found"); 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 we reply to a discord member, ping them!
if (this.bridge.isNamespacedUser(sourceEvent.sender)) { if (this.bridge.isNamespacedUser(sourceEvent.sender)) {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter