This commit is contained in:
Cadence Ember 2023-07-03 17:20:24 +12:00
commit 3578ca28b5
5 changed files with 94 additions and 28 deletions

View file

@ -1,12 +1,37 @@
// @ts-check
/**
* Grab Matrix events we care about, check them, and bridge them.
*/
const assert = require("assert").strict
const {sync, as} = require("../passthrough")
const reg = require("../matrix/read-registration")
/** @type {import("./actions/send-event")} */
const sendEvent = sync.require("./actions/send-event")
// Grab Matrix events we care about for the bridge, check them, and pass them on
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 {import("../types").Event.Outer<any>} event
*/
function eventOriginatedFromDiscord(event) {
if (
// If it's from a user in the bridge's namespace...
userRegex.some(x => event.sender.match(x))
// ...not counting the appservice's own user...
&& !event.sender.startsWith(`@${reg.sender_localpart}:`)
) {
// ...then it originated from discord
return true
}
return false
}
sync.addTemporaryListener(as, "type:m.room.message", event => {
console.log(event)
// TODO: filter out events that were bridged discord messages (i.e. sent by OOYE)
// TODO: call sendMessage
if (eventOriginatedFromDiscord(event)) return
const messageResponses = sendEvent.sendEvent(event)
})