diff --git a/d2m/actions/register-user.js b/d2m/actions/register-user.js index 9b5527f6..b605c3ae 100644 --- a/d2m/actions/register-user.js +++ b/d2m/actions/register-user.js @@ -36,7 +36,7 @@ async function createSim(user) { await api.register(localpart) } catch (e) { // If user creation fails, manually undo the database change. Still isn't perfect, but should help. - // (A transaction would be preferable, but I don't think it's safe to leave transaction open across event loop ticks.) + // (I would prefer a transaction, but it's not safe to leave transactions open across event loop ticks.) db.prepare("DELETE FROM sim WHERE user_id = ?").run(user.id) throw e } diff --git a/scripts/seed.js b/scripts/seed.js index 0f2f23d6..4fc704c1 100644 --- a/scripts/seed.js +++ b/scripts/seed.js @@ -67,6 +67,18 @@ async function uploadAutoEmoji(guild, name, filename) { console.log("✅ Database is ready...") + // ensure appservice bot user is registered... + try { + await api.register(reg.sender_localpart) + } catch (e) { + if (e.data?.error !== "Internal server error") throw e // "Internal server error" is the only OK error because Synapse says this if you try to register the same username twice. + } + + // upload initial images... + const avatarUrl = await file.uploadDiscordFileToMxc("https://cadence.moe/friends/out_of_your_element.png") + + console.log("✅ Matrix appservice login works...") + // upload the L1 L2 emojis to some guild const emojis = db.prepare("SELECT name FROM auto_emoji WHERE name = 'L1' OR name = 'L2'").pluck().all() if (emojis.length !== 2) { @@ -104,11 +116,6 @@ async function uploadAutoEmoji(guild, name, filename) { } console.log("✅ Emojis are 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.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")})