Skip to content
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 a dry run flag to ensure we don't accidentally send out invites when testing #209

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/IRCBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { MatrixClient, MatrixEvent } from "matrix-bot-sdk";
import {LogService, MatrixClient, MatrixEvent} from "matrix-bot-sdk";
import * as irc from "irc-upd";
import { Auditorium } from "./models/Auditorium";
import { InterestRoom } from "./models/InterestRoom";
Expand Down Expand Up @@ -128,7 +128,8 @@ export class IRCBridge {

public async plumbChannelToRoom(channel: string, roomId: string) {
if (await this.shouldInviteBot(roomId)) {
await this.mxClient.inviteUser(this.config.botUserId, roomId);
//await this.mxClient.inviteUser(this.config.botUserId, roomId);
H-Shay marked this conversation as resolved.
Show resolved Hide resolved
LogService.info("IRCBridge", `Inviting ${this.config.botUserId}`)
}
await this.ircClient.join(channel);
const result = await this.executeCommand(`plumb ${roomId} ${this.config.serverName} ${channel}`);
Expand Down
26 changes: 14 additions & 12 deletions src/invites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ export async function resolveIdentifiers(client: ConferenceMatrixClient, people:

export async function invitePersonToRoom(client: ConferenceMatrixClient, resolvedPerson: ResolvedPersonIdentifier, roomId: string): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can slip in a dry-run flag in the config, and just skip this function if so? Worst case, maybe we just override the inviteUser function in ConferenceMatrixClient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A dry run flag is a much better approach - I've added one, let me know what you think.

if (resolvedPerson.mxid) {
return await client.inviteUser(resolvedPerson.mxid.trim(), roomId);
//return await client.inviteUser(resolvedPerson.mxid.trim(), roomId);
LogService.info("invites", `Inviting ${resolvedPerson.mxid}`)
}

if (!resolvedPerson.emails) {
Expand All @@ -93,16 +94,17 @@ export async function invitePersonToRoom(client: ConferenceMatrixClient, resolve
}

for (const email of resolvedPerson.emails) {
const idInvite = await client.identityClient.makeEmailInvite(email, roomId);
const content = {
display_name: idInvite.display_name,
// XXX: https://github.com/matrix-org/matrix-doc/issues/2948
key_validity_url: `${client.identityClient.serverUrl}/_matrix/identity/v2/pubkey/ephemeral/isvalid`,
public_key: idInvite.public_key,
public_keys: idInvite.public_keys,
[RS_3PID_PERSON_ID]: resolvedPerson.person.id,
};
const stateKey = idInvite.token; // not included in the content
await client.sendStateEvent(roomId, "m.room.third_party_invite", stateKey, content);
// const idInvite = await client.identityClient.makeEmailInvite(email, roomId);
// const content = {
// display_name: idInvite.display_name,
// // XXX: https://github.com/matrix-org/matrix-doc/issues/2948
// key_validity_url: `${client.identityClient.serverUrl}/_matrix/identity/v2/pubkey/ephemeral/isvalid`,
// public_key: idInvite.public_key,
// public_keys: idInvite.public_keys,
// [RS_3PID_PERSON_ID]: resolvedPerson.person.id,
// };
// const stateKey = idInvite.token; // not included in the content
// await client.sendStateEvent(roomId, "m.room.third_party_invite", stateKey, content);
LogService.info("invites", `Third-party inviting ${email}`)
}
}
Loading