Cope if the username is already registered
This commit is contained in:
parent
a35860cb15
commit
88a232fb4a
2 changed files with 14 additions and 15 deletions
|
@ -276,15 +276,7 @@ async function validateHomeserverOrigin(serverUrlPrompt, url) {
|
||||||
console.log("✅ Database is ready...")
|
console.log("✅ Database is ready...")
|
||||||
|
|
||||||
// ensure appservice bot user is registered...
|
// ensure appservice bot user is registered...
|
||||||
try {
|
await api.register(reg.sender_localpart)
|
||||||
await api.register(reg.sender_localpart)
|
|
||||||
} catch (e) {
|
|
||||||
if (e.errcode === "M_USER_IN_USE" || e.data?.error === "Internal server error") {
|
|
||||||
// "Internal server error" is the only OK error because older versions of Synapse say this if you try to register the same username twice.
|
|
||||||
} else {
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// upload initial images...
|
// upload initial images...
|
||||||
const avatarUrl = await file.uploadDiscordFileToMxc("https://cadence.moe/friends/out_of_your_element.png")
|
const avatarUrl = await file.uploadDiscordFileToMxc("https://cadence.moe/friends/out_of_your_element.png")
|
||||||
|
|
|
@ -35,14 +35,21 @@ function path(p, mxid, otherParams = {}) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} username
|
* @param {string} username
|
||||||
* @returns {Promise<Ty.R.Registered>}
|
|
||||||
*/
|
*/
|
||||||
function register(username) {
|
async function register(username) {
|
||||||
console.log(`[api] register: ${username}`)
|
console.log(`[api] register: ${username}`)
|
||||||
return mreq.mreq("POST", "/client/v3/register", {
|
try {
|
||||||
type: "m.login.application_service",
|
await mreq.mreq("POST", "/client/v3/register", {
|
||||||
username
|
type: "m.login.application_service",
|
||||||
})
|
username
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
if (e.errcode === "M_USER_IN_USE" || e.data?.error === "Internal server error") {
|
||||||
|
// "Internal server error" is the only OK error because older versions of Synapse say this if you try to register the same username twice.
|
||||||
|
} else {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue