skip "cannot invite user that is joined"
This commit is contained in:
@@ -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
|
// 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}...`)
|
console.log(`-- Joining channel ${channel.name}...`)
|
||||||
await mreq.withAccessToken(oldAT, async () => {
|
await mreq.withAccessToken(oldAT, async () => {
|
||||||
try {
|
|
||||||
await api.inviteToRoom(roomID, newBridgeMxid)
|
await api.inviteToRoom(roomID, newBridgeMxid)
|
||||||
} catch (e) {
|
|
||||||
if (e.message.includes("is already in the room")) {
|
|
||||||
// Great!
|
|
||||||
} else {
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await utils.setUserPower(roomID, newBridgeMxid, 100, api)
|
await utils.setUserPower(roomID, newBridgeMxid, 100, api)
|
||||||
})
|
})
|
||||||
await api.joinRoom(roomID)
|
await api.joinRoom(roomID)
|
||||||
|
|||||||
@@ -87,16 +87,8 @@ async function ensureSimJoined(pkMessage, roomID) {
|
|||||||
// Ensure joined
|
// Ensure joined
|
||||||
const existing = select("sim_member", "mxid", {room_id: roomID, mxid}).pluck().get()
|
const existing = select("sim_member", "mxid", {room_id: roomID, mxid}).pluck().get()
|
||||||
if (!existing) {
|
if (!existing) {
|
||||||
try {
|
|
||||||
await api.inviteToRoom(roomID, mxid)
|
await api.inviteToRoom(roomID, mxid)
|
||||||
await api.joinRoom(roomID, mxid)
|
await api.joinRoom(roomID, mxid)
|
||||||
} catch (e) {
|
|
||||||
if (e.message.includes("is already in the room.")) {
|
|
||||||
// Sweet!
|
|
||||||
} else {
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.prepare("INSERT OR IGNORE INTO sim_member (room_id, mxid) VALUES (?, ?)").run(roomID, mxid)
|
db.prepare("INSERT OR IGNORE INTO sim_member (room_id, mxid) VALUES (?, ?)").run(roomID, mxid)
|
||||||
}
|
}
|
||||||
return mxid
|
return mxid
|
||||||
|
|||||||
@@ -86,16 +86,8 @@ async function ensureSimJoined(user, roomID) {
|
|||||||
// Ensure joined
|
// Ensure joined
|
||||||
const existing = select("sim_member", "mxid", {room_id: roomID, mxid}).pluck().get()
|
const existing = select("sim_member", "mxid", {room_id: roomID, mxid}).pluck().get()
|
||||||
if (!existing) {
|
if (!existing) {
|
||||||
try {
|
|
||||||
await api.inviteToRoom(roomID, mxid)
|
await api.inviteToRoom(roomID, mxid)
|
||||||
await api.joinRoom(roomID, mxid)
|
await api.joinRoom(roomID, mxid)
|
||||||
} catch (e) {
|
|
||||||
if (e.message.includes("is already in the room.")) {
|
|
||||||
// Sweet!
|
|
||||||
} else {
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.prepare("INSERT OR IGNORE INTO sim_member (room_id, mxid) VALUES (?, ?)").run(roomID, mxid)
|
db.prepare("INSERT OR IGNORE INTO sim_member (room_id, mxid) VALUES (?, ?)").run(roomID, mxid)
|
||||||
}
|
}
|
||||||
return mxid
|
return mxid
|
||||||
|
|||||||
@@ -77,16 +77,8 @@ async function ensureSimJoined(fakeUserID, author, roomID) {
|
|||||||
// Ensure joined
|
// Ensure joined
|
||||||
const existing = select("sim_member", "mxid", {room_id: roomID, mxid}).pluck().get()
|
const existing = select("sim_member", "mxid", {room_id: roomID, mxid}).pluck().get()
|
||||||
if (!existing) {
|
if (!existing) {
|
||||||
try {
|
|
||||||
await api.inviteToRoom(roomID, mxid)
|
await api.inviteToRoom(roomID, mxid)
|
||||||
await api.joinRoom(roomID, mxid)
|
await api.joinRoom(roomID, mxid)
|
||||||
} catch (e) {
|
|
||||||
if (e.message.includes("is already in the room.")) {
|
|
||||||
// Sweet!
|
|
||||||
} else {
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.prepare("INSERT OR IGNORE INTO sim_member (room_id, mxid) VALUES (?, ?)").run(roomID, mxid)
|
db.prepare("INSERT OR IGNORE INTO sim_member (room_id, mxid) VALUES (?, ?)").run(roomID, mxid)
|
||||||
}
|
}
|
||||||
return mxid
|
return mxid
|
||||||
|
|||||||
@@ -79,9 +79,17 @@ async function joinRoom(roomIDOrAlias, mxid, via) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function inviteToRoom(roomID, mxidToInvite, mxid) {
|
async function inviteToRoom(roomID, mxidToInvite, mxid) {
|
||||||
|
try {
|
||||||
await mreq.mreq("POST", path(`/client/v3/rooms/${roomID}/invite`, mxid), {
|
await mreq.mreq("POST", path(`/client/v3/rooms/${roomID}/invite`, mxid), {
|
||||||
user_id: mxidToInvite
|
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) {
|
async function leaveRoom(roomID, mxid) {
|
||||||
|
|||||||
Reference in New Issue
Block a user