forked from cadence/out-of-your-element
bridge both ways and prevent reflections
This commit is contained in:
parent
3578ca28b5
commit
39cdba9f90
15 changed files with 67 additions and 51 deletions
21
m2d/converters/utils.js
Normal file
21
m2d/converters/utils.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
// @ts-check
|
||||
|
||||
const reg = require("../../matrix/read-registration")
|
||||
const userRegex = reg.namespaces.users.map(u => new RegExp(u.regex))
|
||||
/**
|
||||
* Determine whether an event is the bridged representation of a discord message.
|
||||
* Such messages shouldn't be bridged again.
|
||||
* @param {string} sender
|
||||
*/
|
||||
function eventSenderIsFromDiscord(sender) {
|
||||
// If it's from a user in the bridge's namespace, then it originated from discord
|
||||
// This includes messages sent by the appservice's bot user, because that is what's used for webhooks
|
||||
// TODO: It would be nice if bridge system messages wouldn't trigger this check and could be bridged from matrix to discord, while webhook reflections would remain ignored...
|
||||
if (userRegex.some(x => sender.match(x))) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
module.exports.eventSenderIsFromDiscord = eventSenderIsFromDiscord
|
Loading…
Add table
Add a link
Reference in a new issue