mirror of
https://gitdab.com/cadence/out-of-your-element.git
synced 2025-09-10 12:22:50 +02:00
glue
This commit is contained in:
parent
6e55e6d1b3
commit
3578ca28b5
5 changed files with 94 additions and 28 deletions
|
@ -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)
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue