diff --git a/addbot.js b/addbot.js index 106ebc1f..4ac55fc0 100644 --- a/addbot.js +++ b/addbot.js @@ -1,7 +1,7 @@ // @ts-check -const config = require("./config") -const token = config.discordToken +const {reg} = require("./src/matrix/read-registration") +const token = reg.ooye.discord_token const id = Buffer.from(token.split(".")[0], "base64").toString() function addbot() { diff --git a/addbot.sh b/addbot.sh index 6c3ff4b7..d40d0daf 100755 --- a/addbot.sh +++ b/addbot.sh @@ -1,3 +1,3 @@ #!/usr/bin/env sh echo "Open this link to add the bot to a Discord server:" -echo "https://discord.com/oauth2/authorize?client_id=$(grep discordToken config.js | sed -E 's!.*: ["'\'']([A-Za-z0-9+=/_-]*).*!\1!g' | base64 -d)&scope=bot&permissions=1610883072" +echo "https://discord.com/oauth2/authorize?client_id=$(grep discord_token registration.yaml | sed -E 's!.*: ["'\'']([A-Za-z0-9+=/_-]*).*!\1!g' | base64 -d)&scope=bot&permissions=1610883072" diff --git a/config.example.js b/config.example.js deleted file mode 100644 index 0d1a29ef..00000000 --- a/config.example.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - discordToken: "yes" -} diff --git a/readme.md b/readme.md index bc190462..7e51cf00 100644 --- a/readme.md +++ b/readme.md @@ -81,11 +81,7 @@ Follow these steps: 1. Install dependencies: `npm install` -1. Copy `config.example.js` to `config.js` and fill in Discord token. - -1. Copy `registration.example.yaml` to `registration.yaml` and fill in bracketed values. You could generate each hex string with `dd if=/dev/urandom bs=32 count=1 2> /dev/null | basenc --base16 | dd conv=lcase 2> /dev/null`. Register the registration in Synapse's `homeserver.yaml` through the usual appservice installation process, then restart Synapse. - -1. Run `node scripts/seed.js` to check your setup and set the bot's initial state. You only need to run this once ever. +1. Run `node scripts/seed.js` to check your setup and set the bot's initial state. It will prompt you for information. You only need to run this once ever. 1. Start the bridge: `node start.js` @@ -113,7 +109,6 @@ To get into the rooms on your Matrix account, either add yourself to `invite` in * Run this to start the bridge: ├── start.js * Runtime configuration, like tokens and user info: - ├── config.js ├── registration.yaml * The bridge's SQLite database is stored here: ├── db diff --git a/src/db/migrations/0011-move-bridge-bot-to-real-id.up.js b/src/db/migrations/0011-move-bridge-bot-to-real-id.up.js index 6bcf2c75..3fab0767 100644 --- a/src/db/migrations/0011-move-bridge-bot-to-real-id.up.js +++ b/src/db/migrations/0011-move-bridge-bot-to-real-id.up.js @@ -10,7 +10,6 @@ */ module.exports = async function(db) { - const config = require("../../../config") - const id = Buffer.from(config.discordToken.split(".")[0], "base64").toString() + const id = require("../../../addbot").id db.prepare("UPDATE OR REPLACE sim SET user_id = ? WHERE user_id = '0'").run(id) } diff --git a/src/passthrough.js b/src/passthrough.js index 18cca6b3..378f5162 100644 --- a/src/passthrough.js +++ b/src/passthrough.js @@ -3,7 +3,6 @@ /** * @typedef {Object} Passthrough * @property {import("repl").REPLServer} repl - * @property {typeof import("./config")} config * @property {import("./d2m/discord-client")} discord * @property {import("heatsync").default} sync * @property {import("better-sqlite3/lib/database")} db diff --git a/src/stdin.js b/src/stdin.js index cabd8ced..90513954 100644 --- a/src/stdin.js +++ b/src/stdin.js @@ -5,7 +5,7 @@ const util = require("util") const {addbot} = require("../addbot") const passthrough = require("./passthrough") -const {discord, config, sync, db} = passthrough +const {discord, sync, db} = passthrough const data = sync.require("../test/data") const createSpace = sync.require("./d2m/actions/create-space") diff --git a/start.js b/start.js index 0e9de144..a9f639a6 100644 --- a/start.js +++ b/start.js @@ -4,18 +4,18 @@ const sqlite = require("better-sqlite3") const migrate = require("./src/db/migrate") const HeatSync = require("heatsync") -const config = require("./config") +const {reg} = require("./src/matrix/read-registration") const passthrough = require("./src/passthrough") const db = new sqlite("src/db/ooye.db") /** @type {import("heatsync").default} */ // @ts-ignore const sync = new HeatSync() -Object.assign(passthrough, {config, sync, db}) +Object.assign(passthrough, {sync, db}) const DiscordClient = require("./src/d2m/discord-client") -const discord = new DiscordClient(config.discordToken, "no") +const discord = new DiscordClient(reg.ooye.discord_token) passthrough.discord = discord const {as} = require("./src/matrix/appservice") @@ -26,7 +26,7 @@ passthrough.from = orm.from passthrough.select = orm.select const power = require("./src/matrix/power.js") -// sync.require("./src/m2d/event-dispatcher") +sync.require("./src/m2d/event-dispatcher") ;(async () => { await migrate.migrate(db) diff --git a/test/test.js b/test/test.js index c898ad1f..ebe49c33 100644 --- a/test/test.js +++ b/test/test.js @@ -13,7 +13,6 @@ const data = require("./data") const fetch = require("node-fetch") const {green} = require("colorette") -const config = require("../config") const passthrough = require("../src/passthrough") const db = new sqlite(":memory:") @@ -46,7 +45,7 @@ const discord = { ]) } -Object.assign(passthrough, { discord, config, sync, db }) +Object.assign(passthrough, { discord, sync, db }) const orm = sync.require("../src/db/orm") passthrough.from = orm.from