-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add more specific errors to CopyModerators
command
#196
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -29,8 +29,21 @@ export class CopyModeratorsCommand implements ICommand { | |||||||||||||
} | ||||||||||||||
const fromRoomId = await this.client.resolveRoom(args[0]); | ||||||||||||||
const toRoomId = await this.client.resolveRoom(args[1]); | ||||||||||||||
const fromPl: {"users"?: Record<string, any>} = await this.client.getRoomStateEvent(fromRoomId, "m.room.power_levels", ""); | ||||||||||||||
let toPl = await this.client.getRoomStateEvent(toRoomId, "m.room.power_levels", ""); | ||||||||||||||
|
||||||||||||||
let fromPl: { "users"?: Record<string, any> } = {} | ||||||||||||||
try { | ||||||||||||||
fromPl = await this.client.getRoomStateEvent(fromRoomId, "m.room.power_levels", ""); | ||||||||||||||
} | ||||||||||||||
catch (error) { | ||||||||||||||
throw Error(`Error fetching or processing power level event from room ${fromRoomId}: ${error.toString()}`) | ||||||||||||||
H-Shay marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
try { | ||||||||||||||
var toPl = await this.client.getRoomStateEvent(toRoomId, "m.room.power_levels", ""); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Avoid using |
||||||||||||||
} | ||||||||||||||
catch (error) { | ||||||||||||||
throw Error(`Error fetching or processing power level event from room ${toRoomId}: ${error.toString()}`) | ||||||||||||||
H-Shay marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if (!toPl) toPl = {}; | ||||||||||||||
if (!toPl['users']) toPl['users'] = {}; | ||||||||||||||
|
@@ -42,14 +55,30 @@ export class CopyModeratorsCommand implements ICommand { | |||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
await this.client.sendStateEvent(toRoomId, "m.room.power_levels", "", toPl); | ||||||||||||||
try { | ||||||||||||||
await this.client.sendStateEvent(toRoomId, "m.room.power_levels", "", toPl); | ||||||||||||||
} | ||||||||||||||
catch (error) { | ||||||||||||||
throw Error(`Error sending new power level event into room ${toRoomId}: ${error.toString()}`) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
const state = await this.client.getRoomState(toRoomId); | ||||||||||||||
let state: any[] = [] | ||||||||||||||
try { | ||||||||||||||
state = await this.client.getRoomState(toRoomId); | ||||||||||||||
} | ||||||||||||||
catch (error) { | ||||||||||||||
throw Error(`Error getting room state from room ${toRoomId}: ${error.toString()}`) | ||||||||||||||
} | ||||||||||||||
const members = state.filter(s => s.type === "m.room.member").map(s => new MembershipEvent(s)); | ||||||||||||||
const effectiveJoinedUserIds = members.filter(m => m.effectiveMembership === "join").map(m => m.membershipFor); | ||||||||||||||
for (const userId of Object.keys(toPl['users'])) { | ||||||||||||||
if (!effectiveJoinedUserIds.includes(userId)) { | ||||||||||||||
await this.client.inviteUser(userId, toRoomId); | ||||||||||||||
try { | ||||||||||||||
await this.client.inviteUser(userId, toRoomId); | ||||||||||||||
} | ||||||||||||||
catch (error) { | ||||||||||||||
throw Error(`Error inviting user ${userId} to room ${toRoomId}: ${error.toString()}`) | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,7 @@ export class HelpCommand implements ICommand { | |
"<pre><code>" + | ||
"!conference inviteme <room> - Asks the bot to invite you to the given room.\n" + | ||
"!conference inviteto <room> <user> - Asks the bot to invite the given user to the given room.\n" + | ||
"!conference join <room> - Makes the bot join the given room.\n" | ||
"!conference join <room> - Makes the bot join the given room.\n" + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was just a typo I noticed that was causing the last two help commands to not be shown in the client. Drive-by cleanup. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hate how JavaScript is happy to have these implied semicolons lead to effectively empty / ignored statements. Thanks for catching it :-) |
||
"!conference copymods <from> <to> - Copies the moderators from one room to another.\n" + | ||
"!conference widgets <aud> - Creates all widgets for the auditorium and its talks.\n" + | ||
"</code></pre>" + | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PowerLevelsEventContent
may also work here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does - much nicer, thanks!