skip "cannot invite user that is joined"

This commit is contained in:
Cadence Ember
2026-01-10 13:19:16 +13:00
parent 505c41a35e
commit 3d3671e05a
5 changed files with 18 additions and 42 deletions

View File

@@ -82,15 +82,7 @@ async function migrateGuild(guild) {
// Step 2: (Using old bridge access token) Join the new bridge to the old rooms and give it PL 100
console.log(`-- Joining channel ${channel.name}...`)
await mreq.withAccessToken(oldAT, async () => {
try {
await api.inviteToRoom(roomID, newBridgeMxid)
} catch (e) {
if (e.message.includes("is already in the room")) {
// Great!
} else {
throw e
}
}
await api.inviteToRoom(roomID, newBridgeMxid)
await utils.setUserPower(roomID, newBridgeMxid, 100, api)
})
await api.joinRoom(roomID)

View File

@@ -87,16 +87,8 @@ async function ensureSimJoined(pkMessage, roomID) {
// Ensure joined
const existing = select("sim_member", "mxid", {room_id: roomID, mxid}).pluck().get()
if (!existing) {
try {
await api.inviteToRoom(roomID, mxid)
await api.joinRoom(roomID, mxid)
} catch (e) {
if (e.message.includes("is already in the room.")) {
// Sweet!
} else {
throw e
}
}
await api.inviteToRoom(roomID, mxid)
await api.joinRoom(roomID, mxid)
db.prepare("INSERT OR IGNORE INTO sim_member (room_id, mxid) VALUES (?, ?)").run(roomID, mxid)
}
return mxid

View File

@@ -86,16 +86,8 @@ async function ensureSimJoined(user, roomID) {
// Ensure joined
const existing = select("sim_member", "mxid", {room_id: roomID, mxid}).pluck().get()
if (!existing) {
try {
await api.inviteToRoom(roomID, mxid)
await api.joinRoom(roomID, mxid)
} catch (e) {
if (e.message.includes("is already in the room.")) {
// Sweet!
} else {
throw e
}
}
await api.inviteToRoom(roomID, mxid)
await api.joinRoom(roomID, mxid)
db.prepare("INSERT OR IGNORE INTO sim_member (room_id, mxid) VALUES (?, ?)").run(roomID, mxid)
}
return mxid

View File

@@ -77,16 +77,8 @@ async function ensureSimJoined(fakeUserID, author, roomID) {
// Ensure joined
const existing = select("sim_member", "mxid", {room_id: roomID, mxid}).pluck().get()
if (!existing) {
try {
await api.inviteToRoom(roomID, mxid)
await api.joinRoom(roomID, mxid)
} catch (e) {
if (e.message.includes("is already in the room.")) {
// Sweet!
} else {
throw e
}
}
await api.inviteToRoom(roomID, mxid)
await api.joinRoom(roomID, mxid)
db.prepare("INSERT OR IGNORE INTO sim_member (room_id, mxid) VALUES (?, ?)").run(roomID, mxid)
}
return mxid

View File

@@ -79,9 +79,17 @@ async function joinRoom(roomIDOrAlias, mxid, via) {
}
async function inviteToRoom(roomID, mxidToInvite, mxid) {
await mreq.mreq("POST", path(`/client/v3/rooms/${roomID}/invite`, mxid), {
user_id: mxidToInvite
})
try {
await mreq.mreq("POST", path(`/client/v3/rooms/${roomID}/invite`, mxid), {
user_id: mxidToInvite
})
} catch (e) {
if (e.message.includes("is already in the room.") || e.message.includes("cannot invite user that is joined")) {
// Sweet!
} else {
throw e
}
}
}
async function leaveRoom(roomID, mxid) {