Remove token from config file

This commit is contained in:
Cadence Ember 2024-09-13 23:47:11 +12:00
parent c0d92ea66d
commit cc7831a313
9 changed files with 11 additions and 22 deletions

View file

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

View file

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

View file

@ -1,3 +0,0 @@
module.exports = {
discordToken: "yes"
}

View file

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

View file

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

View file

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

View file

@ -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")

View file

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

View file

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