Skip to content

Commit

Permalink
tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Jan 20, 2025
1 parent 4274650 commit aa86940
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
10 changes: 5 additions & 5 deletions src/Mjolnir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,11 @@ export class Mjolnir {

matrixEmitter.on("room.message", async (roomId, event) => {
const eventContent = event.content;
const eventId = event.event_id;
const sender = event.sender;
if (typeof eventContent !== "object") return;

const { msgtype, body: originalBody, sender, event_id } = eventContent;
const { msgtype, body: originalBody } = eventContent;

if (msgtype !== "m.text" || typeof originalBody !== "string") {
return;
Expand All @@ -236,9 +238,7 @@ export class Mjolnir {
return;
}
this.lastBotMentionForRoomId.set(roomId, true);
const permalink = Permalinks.forEvent(roomId, event_id, [
new UserID(this.clientUserId).domain,
]);
const permalink = Permalinks.forEvent(roomId, eventId, [new UserID(this.clientUserId).domain]);
await this.managementRoomOutput.logMessage(
LogLevel.INFO,
"Mjolnir",
Expand Down Expand Up @@ -280,7 +280,7 @@ export class Mjolnir {
eventContent.body = COMMAND_PREFIX + restOfBody;
LogService.info("Mjolnir", `Command being run by ${sender}: ${eventContent.body}`);

client.sendReadReceipt(roomId, event_id).catch((e: any) => {
client.sendReadReceipt(roomId, eventId).catch((e: any) => {
LogService.warn("Mjolnir", "Error sending read receipt: ", e);
});
return handleCommand(roomId, event, this);
Expand Down
34 changes: 20 additions & 14 deletions test/integration/commands/commandHandlerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,30 @@ describe("Test: General command handling test", function () {
visibility: "public",
});
await this.moderator.sendText(this.mjolnir.managementRoomId, `!mjolnir rooms add ${publicRoomId}`);
const joinPromise = new Promise<void>((resolve) => this.userA.on("room.event", (roomId, evt) => {
if (roomId === publicRoomId && evt.type === "m.room.member" && evt.state_key === mjolnirUserId && evt.content.membership === "join") {
resolve();
}
}));
const joinPromise = new Promise<void>((resolve) =>
this.userA.on("room.event", (roomId, evt) => {
if (
roomId === publicRoomId &&
evt.type === "m.room.member" &&
evt.state_key === mjolnirUserId &&
evt.content.membership === "join"
) {
resolve();
}
}),
);
await this.userA.inviteUser(mjolnirUserId, publicRoomId);
await joinPromise;
await this.userA.sendText(publicRoomId, "!mjolnir enable MentionSpam");

const reply = new Promise<null|unknown>(
(resolve, reject) => {
// Mjolnir should ignore our message entirely.
setTimeout(() => resolve(null), 10000);
getFirstReply(this.userA, publicRoomId, () => this.userA.sendText(publicRoomId, "!mjolnir status")).then(resolve).catch(reject);
}
);
const reply = new Promise<null | unknown>((resolve, reject) => {
// Mjolnir should ignore our message entirely.
setTimeout(() => resolve(null), 10000);
getFirstReply(this.userA, publicRoomId, () => this.userA.sendText(publicRoomId, "!mjolnir status"))
.then(resolve)
.catch(reject);
});

expect(await reply).toBeNull();
});

});

0 comments on commit aa86940

Please sign in to comment.