summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorCadence Ember <cadence@disroot.org>2023-10-07 21:57:09 +1300
committerCadence Ember <cadence@disroot.org>2023-10-07 21:57:09 +1300
commit0b40a5025498f1e84cddf2ceb14c51ec9b91bcd7 (patch)
tree94caf46588725cb0b9cd6169fc723cf2ac4635e6 /scripts
parentFix emoji_id references and add tests (diff)
downloadout-of-your-element-0b40a5025498f1e84cddf2ceb14c51ec9b91bcd7.tar.xz
Set profile data in seed.js
Diffstat (limited to 'scripts')
-rw-r--r--scripts/seed.js29
1 files changed, 25 insertions, 4 deletions
diff --git a/scripts/seed.js b/scripts/seed.js

index 3b24768..2a0c279 100644 --- a/scripts/seed.js +++ b/scripts/seed.js
@@ -12,7 +12,15 @@ const migrate = require("../db/migrate") 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 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(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 + console.log("✅ Configuration looks good...") // database ddl... 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... // 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... await api.profileSetDisplayname(mxid, "Out Of Your Element") await api.profileSetAvatarUrl(mxid, avatarUrl) + console.log("✅ Matrix profile updated...") - // add initial rows to database, like adding the bot to sim... - 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) + console.log("Good to go. I hope you enjoy Out Of Your Element.") + process.exit() })()