arrange files even more

This commit is contained in:
Cadence Ember 2023-09-06 13:07:05 +12:00
parent 5b2ccdc1f8
commit 3899c01663
4 changed files with 62 additions and 48 deletions

View File

@ -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.

42
scripts/seed.js Normal file
View File

@ -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)
})()

35
seed.js
View File

@ -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...
})()

View File