diff --git a/src/commands/FDMCommand.ts b/src/commands/FDMCommand.ts index 697f945..dc79ff0 100644 --- a/src/commands/FDMCommand.ts +++ b/src/commands/FDMCommand.ts @@ -29,9 +29,30 @@ export class FDMCommand implements ICommand { public async run(roomId: string, event: any, args: string[]) { const spi = this.conference.getInterestRoom("I.infodesk"); - const infBackstage = await this.client.resolveRoom("#infodesk-backstage:fosdem.org"); - const vol = await this.client.resolveRoom("#volunteers:fosdem.org"); - const volBackstage = await this.client.resolveRoom("#volunteers-backstage:fosdem.org"); + + let infBackstage; + try { + infBackstage = await this.client.resolveRoom("#infodesk-backstage:fosdem.org"); + } + catch (error) { + throw Error(`Error resolving the roomID for room #infodesk-backstage:fosdem.org`, {cause: error}) + } + + let vol; + try { + vol = await this.client.resolveRoom("#volunteers:fosdem.org"); + } + catch (error) { + throw Error(`Error resolving the roomID for room #volunteers:fosdem.org`, {cause: error}) + } + + let volBackstage; + try { + volBackstage = await this.client.resolveRoom("#volunteers-backstage:fosdem.org"); + } + catch (error) { + throw Error(`Error resolving the roomID for room #volunteers-backstage:fosdem.org`, {cause: error}) + } const db = await this.conference.getPentaDb(); if (db === null) { @@ -39,7 +60,14 @@ export class FDMCommand implements ICommand { return; } - let volunteers = await db.findAllPeopleWithRemark("volunteer"); + let volunteers; + try { + volunteers = await db.findAllPeopleWithRemark("volunteer"); + } + catch (error) { + throw Error('There was an error fetching volunteers from the database', {cause:error}) + } + const dedupe: IPerson[] = []; for (const volunteer of volunteers) { if (!dedupe.some(p => p.id === volunteer.id)) { @@ -58,9 +86,32 @@ export class FDMCommand implements ICommand { } else if (args[0] === 'invite') { const infodesk = await this.conference.getInviteTargetsForInterest(spi); const infodeskResolved = await resolveIdentifiers(this.client, infodesk); - const inBsJoined = await this.client.getJoinedRoomMembers(infBackstage); - const volJoined = await this.client.getJoinedRoomMembers(vol); - const volBsJoined = await this.client.getJoinedRoomMembers(volBackstage); + + let inBsJoined; + try { + inBsJoined = await this.client.getJoinedRoomMembers(infBackstage); + } + catch (error) { + throw Error(`Error fetching the members of the room #infodesk-backstage:fosdem.org`, {cause: error}) + } + + let volJoined; + try { + volJoined = await this.client.getJoinedRoomMembers(vol); + } + catch (error) { + throw Error(`Error fetching the members of the room #volunteers:fosdem.org`, {cause:error}) + } + + let volBsJoined; + try { + volBsJoined = await this.client.getJoinedRoomMembers(volBackstage); + } + catch (error) { + throw Error("Error fetching members of the room #volunteers-backstage:fosdem.org", {cause:error}) + } + + for (const person of infodeskResolved) { try { if (person.mxid && inBsJoined.includes(person.mxid)) continue; diff --git a/src/commands/InviteCommand.ts b/src/commands/InviteCommand.ts index 1e0602c..efaa840 100644 --- a/src/commands/InviteCommand.ts +++ b/src/commands/InviteCommand.ts @@ -33,7 +33,13 @@ export class InviteCommand implements ICommand { private async createInvites(people: IPerson[], alias: string) { const resolved = await resolveIdentifiers(this.client, people); - const targetRoomId = await this.client.resolveRoom(alias); + let targetRoomId; + try { + targetRoomId = await this.client.resolveRoom(alias); + } + catch (error) { + throw Error(`Error resolving room id for ${alias}`, {cause: error}) + } await this.ensureInvited(targetRoomId, resolved); } @@ -94,7 +100,13 @@ export class InviteCommand implements ICommand { public async ensureInvited(roomId: string, people: ResolvedPersonIdentifier[]) { // We don't want to invite anyone we have already invited or that has joined though, so // avoid those people. We do this by querying the room state and filtering. - const state = await this.client.getRoomState(roomId); + let state; + try { + state = await this.client.getRoomState(roomId); + } + catch (error) { + throw Error(`Error fetching state for room ${roomId}`, {cause: error}) + } const emailInvitePersonIds = state.filter(s => s.type === "m.room.third_party_invite").map(s => s.content?.[RS_3PID_PERSON_ID]).filter(i => !!i); 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); diff --git a/src/commands/InviteMeCommand.ts b/src/commands/InviteMeCommand.ts index f4fc010..776364f 100644 --- a/src/commands/InviteMeCommand.ts +++ b/src/commands/InviteMeCommand.ts @@ -27,7 +27,13 @@ export class InviteMeCommand implements ICommand { public readonly prefixes = ["inviteme", "inviteto"]; private async inviteTo(invitee: string, room: string): Promise { - const members = await this.client.getJoinedRoomMembers(room); + let members; + try { + members = await this.client.getJoinedRoomMembers(room); + } + catch (error) { + throw Error(`Error getting joined members from room ${room}`, {cause:error}) + } if (members.includes(invitee)) return; await this.client.inviteUser(invitee, room); } @@ -137,8 +143,19 @@ export class InviteMeCommand implements ICommand { await this.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅'); } else { // Invite to one particular room. - const targetRoomId = await this.client.resolveRoom(args[0]); - await this.client.inviteUser(userId, targetRoomId); + let targetRoomId; + try { + targetRoomId = await this.client.resolveRoom(args[0]); + } + catch (error) { + throw Error(`Error resolving room ${args[0]}`, {cause:error}) + } + try { + await this.client.inviteUser(userId, targetRoomId); + } + catch (error) { + throw Error(`Error inviting ${userId} to ${targetRoomId}`, {cause:error}) + } await this.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅'); } } diff --git a/src/commands/JoinRoomCommand.ts b/src/commands/JoinRoomCommand.ts index 8281f37..0cd17c4 100644 --- a/src/commands/JoinRoomCommand.ts +++ b/src/commands/JoinRoomCommand.ts @@ -32,7 +32,12 @@ export class JoinCommand implements ICommand { await this.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '⌛️'); - await this.client.joinRoom(args[0], []); + try { + await this.client.joinRoom(args[0], []); + } + catch (error) { + throw Error(`Error joining room ${args[0]}`, {cause:error}) + } await this.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅'); } diff --git a/src/commands/PermissionsCommand.ts b/src/commands/PermissionsCommand.ts index dd51692..acce283 100644 --- a/src/commands/PermissionsCommand.ts +++ b/src/commands/PermissionsCommand.ts @@ -39,12 +39,25 @@ export class PermissionsCommand implements ICommand { } public static async ensureModerator(client: MatrixClient, roomId: string, people: ResolvedPersonIdentifier[]) { - const powerLevels = await client.getRoomStateEvent(roomId, "m.room.power_levels", ""); + let powerLevels; + try { + powerLevels = await client.getRoomStateEvent(roomId, "m.room.power_levels", ""); + } + catch (error) { + throw Error(`Error fetching power levels for room ${roomId}`, {cause:error}) + } + for (const person of people) { if (!person.mxid) continue; if (powerLevels['users'][person.mxid]) continue; powerLevels['users'][person.mxid] = 50; } - await client.sendStateEvent(roomId, "m.room.power_levels", "", powerLevels); + + try { + await client.sendStateEvent(roomId, "m.room.power_levels", "", powerLevels); + } + catch (error) { + throw Error(`Error sending powerlevels event into room ${roomId}`, {cause:error}) + } } }