rename onReactionTo to getFirstReaction

This commit is contained in:
gnuxie 2021-12-03 17:17:23 +00:00
parent 1a65122b0d
commit 7ee3ce1dd2
2 changed files with 5 additions and 5 deletions

View File

@ -9,7 +9,7 @@ import { MatrixClient } from "matrix-bot-sdk";
* @param targetEventThunk A function that produces an event ID when called. This event ID is then used to listen for a reaction. * @param targetEventThunk A function that produces an event ID when called. This event ID is then used to listen for a reaction.
* @returns The reaction event. * @returns The reaction event.
*/ */
export async function onReactionTo(client: MatrixClient, targetRoom: string, reactionKey: string, targetEventThunk: () => Promise<string>): Promise<any> { export async function getFirstReaction(client: MatrixClient, targetRoom: string, reactionKey: string, targetEventThunk: () => Promise<string>): Promise<any> {
let reactionEvents = []; let reactionEvents = [];
const addEvent = function (roomId, event) { const addEvent = function (roomId, event) {
if (roomId !== targetRoom) return; if (roomId !== targetRoom) return;

View File

@ -4,7 +4,7 @@ import config from "../../../src/config";
import { newTestUser } from "../clientHelper"; import { newTestUser } from "../clientHelper";
import { getMessagesByUserIn } from "../../../src/utils"; import { getMessagesByUserIn } from "../../../src/utils";
import { LogService } from "matrix-bot-sdk"; import { LogService } from "matrix-bot-sdk";
import { onReactionTo } from "./commandUtils"; import { getFirstReaction } from "./commandUtils";
describe("Test: The redaction command", function () { describe("Test: The redaction command", function () {
it('Mjölnir redacts all of the events sent by a spammer when instructed to by giving their id and a room id.', async function() { it('Mjölnir redacts all of the events sent by a spammer when instructed to by giving their id and a room id.', async function() {
@ -34,7 +34,7 @@ import { onReactionTo } from "./commandUtils";
try { try {
moderator.start(); moderator.start();
await onReactionTo(moderator, this.mjolnir.managementRoomId, '✅', async () => { await getFirstReaction(moderator, this.mjolnir.managementRoomId, '✅', async () => {
return await moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text', body: `!mjolnir redact ${badUserId} ${targetRoom}` }); return await moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text', body: `!mjolnir redact ${badUserId} ${targetRoom}` });
}); });
} finally { } finally {
@ -81,7 +81,7 @@ import { onReactionTo } from "./commandUtils";
try { try {
moderator.start(); moderator.start();
await onReactionTo(moderator, this.mjolnir.managementRoomId, '✅', async () => { await getFirstReaction(moderator, this.mjolnir.managementRoomId, '✅', async () => {
return await moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text', body: `!mjolnir redact ${badUserId}` }); return await moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text', body: `!mjolnir redact ${badUserId}` });
}); });
} finally { } finally {
@ -117,7 +117,7 @@ import { onReactionTo } from "./commandUtils";
try { try {
moderator.start(); moderator.start();
await onReactionTo(moderator, this.mjolnir.managementRoomId, '✅', async () => { await getFirstReaction(moderator, this.mjolnir.managementRoomId, '✅', async () => {
return await moderator.sendMessage(this.mjolnir.managementRoomId, {msgtype: 'm.text', body: `!mjolnir redact https://matrix.to/#/${encodeURIComponent(targetRoom)}/${encodeURIComponent(eventToRedact)}`}); return await moderator.sendMessage(this.mjolnir.managementRoomId, {msgtype: 'm.text', body: `!mjolnir redact https://matrix.to/#/${encodeURIComponent(targetRoom)}/${encodeURIComponent(eventToRedact)}`});
}); });
} finally { } finally {