From d70199f890f546d3f8e5da2809708f6f6ee2f68b Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Thu, 29 Jun 2023 08:08:17 +1200 Subject: [PATCH] add appservice listener --- index.js | 7 ++++++- m2d/appservice.js | 8 ++++++++ m2d/event-dispatcher.js | 8 ++++++++ passthrough.js | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 m2d/appservice.js create mode 100644 m2d/event-dispatcher.js diff --git a/index.js b/index.js index 807b49f2..f4c59c64 100644 --- a/index.js +++ b/index.js @@ -9,13 +9,18 @@ const db = new sqlite("db/ooye.db") const sync = new HeatSync() -Object.assign(passthrough, { config, sync, db }) +Object.assign(passthrough, {config, sync, db}) const DiscordClient = require("./d2m/discord-client") const discord = new DiscordClient(config.discordToken) passthrough.discord = discord +const as = require("./m2d/appservice") +passthrough.as = as + +sync.require("./m2d/event-dispatcher") + ;(async () => { await discord.cloud.connect() console.log("Discord gateway started") diff --git a/m2d/appservice.js b/m2d/appservice.js new file mode 100644 index 00000000..e99a8223 --- /dev/null +++ b/m2d/appservice.js @@ -0,0 +1,8 @@ +const reg = require("../matrix/read-registration") +const AppService = require("matrix-appservice").AppService +const as = new AppService({ + homeserverToken: reg.hs_token +}) +as.listen(+(new URL(reg.url).port)) + +module.exports = as diff --git a/m2d/event-dispatcher.js b/m2d/event-dispatcher.js new file mode 100644 index 00000000..136aae0c --- /dev/null +++ b/m2d/event-dispatcher.js @@ -0,0 +1,8 @@ +const assert = require("assert").strict +const {sync, as} = require("../passthrough") + +// Grab Matrix events we care about for the bridge, check them, and pass them on + +sync.addTemporaryListener(as, "type:m.room.message", event => { + console.log(event) +}) diff --git a/passthrough.js b/passthrough.js index 8ef75dbc..16de1bb2 100644 --- a/passthrough.js +++ b/passthrough.js @@ -7,6 +7,7 @@ * @property {import("./d2m/discord-client")} discord * @property {import("heatsync")} sync * @property {import("better-sqlite3/lib/database")} db + * @property {import("matrix-appservice").AppService} as */ /** @type {Passthrough} */ // @ts-ignore