From 3899c01663a394861e9084222528ddc84b6d4b84 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Wed, 6 Sep 2023 13:07:05 +1200 Subject: [PATCH] arrange files even more --- readme.md | 33 ++++++++++++++++++++------------- scripts/seed.js | 42 ++++++++++++++++++++++++++++++++++++++++++ seed.js | 35 ----------------------------------- index.js => start.js | 0 4 files changed, 62 insertions(+), 48 deletions(-) create mode 100644 scripts/seed.js delete mode 100644 seed.js rename index.js => start.js (100%) diff --git a/readme.md b/readme.md index 64b3293..5cf6971 100644 --- a/readme.md +++ b/readme.md @@ -20,7 +20,7 @@ Most features you'd expect in both directions, plus a little extra spice: * Reactions * Mentions * Replies -* Theads +* Threads * Stickers * Attachments * Spoiler attachments @@ -33,6 +33,7 @@ Most features you'd expect in both directions, plus a little extra spice: * Custom emojis don't fully work yet. * Embeds don't work yet. +* This bridge is not designed for puppetting. * Some aspects of this bridge are customised for my homeserver. I'm working over time to make it more general. Please please reach out to @cadence:cadence.moe if you would like to run this, and I'll work with you to get it running! # Development information @@ -56,15 +57,21 @@ Copy `registration.example.yaml` to `registration.yaml` and fill in bracketed va If developing on a different computer to the one running the homeserver, use SSH port forwarding so that Synapse can connect on its `localhost:6693` to reach the running bridge on your computer. Example: `ssh -T -v -R 6693:localhost:6693 username@matrix.cadence.moe` +Run `node scripts/seed.js` to check your setup, then create the database and server state (only need to run this once ever) + Make sure the tests work: `npm t` -I recommend developing in Visual Studio Code so that the JSDoc x TypeScript annotations work. I don't know what other editors or language servers support annotations and type inference. +Start the bridge: `node start.js` + +Any files you change will automatically be reloaded, except for `stdin.js` and `d2m/discord-*.js` + +I recommend developing in Visual Studio Code so that the JSDoc x TypeScript annotation comments work. I don't know which other editors or language servers support annotations and type inference. ## Repository structure . - * Entrypoint: - ├── index.js + * Run this to start the bridge: + ├── start.js * Runtime configuration, like tokens and user info: ├── config.js ├── registration.yaml @@ -91,30 +98,30 @@ I recommend developing in Visual Studio Code so that the JSDoc x TypeScript anno │   ├── converters │   │   └── *.js │   └── event-dispatcher.js - * We aren't using the matrix-js-sdk, so here's all the stuff we need to call the Matrix CS API: + * We aren't using the matrix-js-sdk, so here's all the stuff we need to call the Matrix C-S API: ├── matrix │   └── *.js * Various files you can run once if you need them. Hopefully you won't need them. ├── scripts - │   └── *.js - * First time running a new bridge? Run this file to plant a seed, which will flourish into state for the bridge: - ├── seed.js - * You are here :) + │   ├── *.js + │   * First time running a new bridge? Run this file to plant a seed, which will flourish into state for the bridge: + │   └── seed.js + * You are here! :) └── readme.md ## Dependency justification -(transitive dependency count) dependency name: explanation +(deduped transitive dependency count) dependency name: explanation -* (0) @chriscdn/promise-semaphore -* (50) better-sqlite3: SQLite3 is the best database, and this is the best library for it. Really! I love it. +* (0) @chriscdn/promise-semaphore: It does what I want! I like it! +* (42) better-sqlite3: SQLite3 is the best database, and this is the best library for it. Really! I love it. * (1) chunk-text: It does what I want. * (0) cloudstorm: Discord gateway library with bring-your-own-caching that I trust. * (8) snowtransfer: Discord API library with bring-your-own-caching that I trust. * (1) discord-markdown: This is my fork! I make sure it does what I want. * (1) heatsync: Module hot-reloader that I trust. * (1) js-yaml: It seems to do what I want, and it's already pulled in by matrix-appservice. -* (115) matrix-appservice: I wish it didn't pull in express :( +* (70) matrix-appservice: I wish it didn't pull in express :( * (0) mixin-deep: This is my fork! It fixes a bug in regular mixin-deep. * (3) node-fetch@2: I like it and it does what I want. * (0) prettier-bytes: It does what I want and has no dependencies. diff --git a/scripts/seed.js b/scripts/seed.js new file mode 100644 index 0000000..444cee9 --- /dev/null +++ b/scripts/seed.js @@ -0,0 +1,42 @@ +// @ts-check + +const assert = require("assert").strict +const fs = require("fs") +const sqlite = require("better-sqlite3") +const HeatSync = require("heatsync") + +const config = require("../config") +const passthrough = require("../passthrough") +const db = new sqlite("db/ooye.db") + +const sync = new HeatSync({watchFS: false}) + +Object.assign(passthrough, { config, sync, db }) + +const api = require("../matrix/api") +const file = require("../matrix/file") +const reg = require("../matrix/read-registration") +const utils = require("../m2d/converters/utils") + +;(async () => { + const mxid = `@${reg.sender_localpart}:${reg.ooye.server_name}` + + // ensure registration is correctly set... + assert(reg.sender_localpart.startsWith(reg.ooye.namespace_prefix)) + assert(utils.eventSenderIsFromDiscord(mxid)) + + // ensure homeserver well-known is valid and returns reg.ooye.server_name... + + // upload initial images... + const avatarUrl = await file.uploadDiscordFileToMxc("https://cadence.moe/friends/out_of_your_element_rev_2.jpg") + + // set profile data on homeserver... + await api.profileSetDisplayname(mxid, "Out Of Your Element") + await api.profileSetAvatarUrl(mxid, avatarUrl) + + // database ddl... + db.exec(fs.readFileSync("db/ooye-schema.sql", "utf8")) + + // add initial rows to database, like adding the bot to sim... + db.prepare("INSERT INTO sim (discord_id, sim_name, localpart, mxid) VALUES (?, ?, ?, ?)").run("0", reg.sender_localpart.slice(reg.ooye.namespace_prefix.length), reg.sender_localpart, mxid) +})() diff --git a/seed.js b/seed.js deleted file mode 100644 index e513f63..0000000 --- a/seed.js +++ /dev/null @@ -1,35 +0,0 @@ -// @ts-check - -const assert = require("assert") -const sqlite = require("better-sqlite3") -const HeatSync = require("heatsync") - -const config = require("./config") -const passthrough = require("./passthrough") -const db = new sqlite("db/ooye.db") - -const sync = new HeatSync({watchFS: false}) - -Object.assign(passthrough, { config, sync, db }) - -const api = require("./matrix/api") -const file = require("./matrix/file") -const reg = require("./matrix/read-registration") - -;(async () => { - // ensure registration is correctly set... - - // test connection to homeserver... - - // upload initial images... - const avatarUrl = await file.uploadDiscordFileToMxc("https://cadence.moe/friends/out_of_your_element_rev_2.jpg") - - // set profile data on homeserver... - await api.profileSetDisplayname(`@${reg.sender_localpart}:${reg.ooye.server_name}`, "Out Of Your Element") - await api.profileSetAvatarUrl(`@${reg.sender_localpart}:${reg.ooye.server_name}`, avatarUrl) - - // database ddl... - - // add initial rows to database, like adding the bot to sim... - -})() diff --git a/index.js b/start.js similarity index 100% rename from index.js rename to start.js