1
0
Fork 0

Set profile data in seed.js

This commit is contained in:
Cadence Ember 2023-10-07 21:57:09 +13:00
parent e3b2c844d8
commit 0b40a50254
3 changed files with 26 additions and 7 deletions

View file

@ -25,7 +25,6 @@ const utils = {
client.application = message.d.application client.application = message.d.application
console.log(`Discord logged in as ${client.user.username}#${client.user.discriminator} (${client.user.id})`) console.log(`Discord logged in as ${client.user.username}#${client.user.discriminator} (${client.user.id})`)
} else if (message.t === "GUILD_CREATE") { } else if (message.t === "GUILD_CREATE") {
client.guilds.set(message.d.id, message.d) client.guilds.set(message.d.id, message.d)
const arr = [] const arr = []

View file

@ -73,8 +73,7 @@ Follow these steps:
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. 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, create the database and server state (only need to run this once ever) 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. Make sure the tests work by running `npm t` 1. Make sure the tests work by running `npm t`
1. Start the bridge: `node start.js` 1. Start the bridge: `node start.js`

View file

@ -12,7 +12,15 @@ const migrate = require("../db/migrate")
const sync = new HeatSync({watchFS: false}) const sync = new HeatSync({watchFS: false})
Object.assign(passthrough, { config, sync, db }) Object.assign(passthrough, { sync, config, db })
const orm = sync.require("../db/orm")
passthrough.from = orm.from
passthrough.select = orm.select
const DiscordClient = require("../d2m/discord-client")
const discord = new DiscordClient(config.discordToken, "no")
passthrough.discord = discord
const api = require("../matrix/api") const api = require("../matrix/api")
const file = require("../matrix/file") const file = require("../matrix/file")
@ -27,19 +35,32 @@ const utils = require("../m2d/converters/utils")
assert(utils.eventSenderIsFromDiscord(mxid)) // appservice's mxid must be in the namespace it controls assert(utils.eventSenderIsFromDiscord(mxid)) // appservice's mxid must be in the namespace it controls
assert(reg.ooye.server_origin.match(/^https?:\/\//)) // must start with http or https assert(reg.ooye.server_origin.match(/^https?:\/\//)) // must start with http or https
assert.notEqual(reg.ooye.server_origin.slice(-1), "/") // must not end in slash assert.notEqual(reg.ooye.server_origin.slice(-1), "/") // must not end in slash
console.log("✅ Configuration looks good...")
// database ddl... // database ddl...
await migrate.migrate(db) await migrate.migrate(db)
// add initial rows to database, like adding the bot to sim...
db.prepare("INSERT OR IGNORE INTO sim (user_id, sim_name, localpart, mxid) VALUES (?, ?, ?, ?)").run("0", reg.sender_localpart.slice(reg.ooye.namespace_prefix.length), reg.sender_localpart, mxid)
console.log("✅ Database is ready...")
// ensure homeserver well-known is valid and returns reg.ooye.server_name... // ensure homeserver well-known is valid and returns reg.ooye.server_name...
// upload initial images... // upload initial images...
const avatarUrl = await file.uploadDiscordFileToMxc("https://cadence.moe/friends/out_of_your_element_rev_2.jpg") const avatarUrl = await file.uploadDiscordFileToMxc("https://cadence.moe/friends/out_of_your_element.png")
// set profile data on discord...
const avatarImageBuffer = await fetch("https://cadence.moe/friends/out_of_your_element.png").then(res => res.arrayBuffer())
await discord.snow.user.updateSelf({avatar: "data:image/png;base64," + Buffer.from(avatarImageBuffer).toString("base64")})
await discord.snow.requestHandler.request(`/applications/@me`, {}, "patch", "json", {description: "Powered by **Out Of Your Element**\nhttps://gitdab.com/cadence/out-of-your-element"})
console.log("✅ Discord profile updated...")
// set profile data on homeserver... // set profile data on homeserver...
await api.profileSetDisplayname(mxid, "Out Of Your Element") await api.profileSetDisplayname(mxid, "Out Of Your Element")
await api.profileSetAvatarUrl(mxid, avatarUrl) await api.profileSetAvatarUrl(mxid, avatarUrl)
console.log("✅ Matrix profile updated...")
// add initial rows to database, like adding the bot to sim... console.log("Good to go. I hope you enjoy Out Of Your Element.")
db.prepare("INSERT INTO sim (user_id, sim_name, localpart, mxid) VALUES (?, ?, ?, ?)").run("0", reg.sender_localpart.slice(reg.ooye.namespace_prefix.length), reg.sender_localpart, mxid) process.exit()
})() })()