mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 01:36:06 -04:00
Test for ban reasons as well in autodetection
This commit is contained in:
parent
66a5775136
commit
417673aeef
@ -70,14 +70,19 @@ export async function parseArguments(roomId: string, event: any, mjolnir: Mjolni
|
||||
if (entity) break;
|
||||
}
|
||||
|
||||
if (!list) {
|
||||
list = mjolnir.lists.find(b => b.listShortcode.toLowerCase() === defaultShortcode);
|
||||
if (!entity) {
|
||||
// It'll be a server at this point - figure out which positional argument is the server
|
||||
// name and where the reason starts.
|
||||
let serverIndex = 2;
|
||||
if (ruleType) serverIndex++;
|
||||
if (list) serverIndex++;
|
||||
entity = parts[serverIndex];
|
||||
if (!ruleType) ruleType = RULE_SERVER;
|
||||
argumentIndex = serverIndex + 1;
|
||||
}
|
||||
|
||||
if (!entity) {
|
||||
entity = parts[argumentIndex - 1];
|
||||
if (!ruleType) ruleType = RULE_SERVER; // due to the conditions above, it can't be anything else
|
||||
console.log(parts);
|
||||
if (!list) {
|
||||
list = mjolnir.lists.find(b => b.listShortcode.toLowerCase() === defaultShortcode);
|
||||
}
|
||||
|
||||
let replyMessage = null;
|
||||
|
@ -62,6 +62,23 @@ describe("UnbanBanCommand", () => {
|
||||
expect(bits.list.listShortcode).toBe("test");
|
||||
});
|
||||
|
||||
it("should be able to detect servers with ban reasons", async () => {
|
||||
const mjolnir = createTestMjolnir();
|
||||
(<any>mjolnir).lists = [{listShortcode: "test"}];
|
||||
mjolnir.client.sendMessage = (roomId: string, content: any): Promise<string> => {
|
||||
throw new Error("sendMessage should not have been called: " + JSON.stringify(content));
|
||||
};
|
||||
|
||||
const command = "!mjolnir ban test example.org reason here";
|
||||
const bits = await parseArguments("!a", createFakeEvent(command), mjolnir, command.split(' '));
|
||||
expect(bits).toBeTruthy();
|
||||
expect(bits.reason).toBe("reason here");
|
||||
expect(bits.ruleType).toBe(RULE_SERVER);
|
||||
expect(bits.entity).toBe("example.org");
|
||||
expect(bits.list).toBeDefined();
|
||||
expect(bits.list.listShortcode).toBe("test");
|
||||
});
|
||||
|
||||
it("should be able to detect servers with globs", async () => {
|
||||
const mjolnir = createTestMjolnir();
|
||||
(<any>mjolnir).lists = [{listShortcode: "test"}];
|
||||
@ -113,6 +130,23 @@ describe("UnbanBanCommand", () => {
|
||||
expect(bits.list.listShortcode).toBe("test");
|
||||
});
|
||||
|
||||
it("should be able to detect room IDs with ban reasons", async () => {
|
||||
const mjolnir = createTestMjolnir();
|
||||
(<any>mjolnir).lists = [{listShortcode: "test"}];
|
||||
mjolnir.client.sendMessage = (roomId: string, content: any): Promise<string> => {
|
||||
throw new Error("sendMessage should not have been called: " + JSON.stringify(content));
|
||||
};
|
||||
|
||||
const command = "!mjolnir ban test !example.org reason here";
|
||||
const bits = await parseArguments("!a", createFakeEvent(command), mjolnir, command.split(' '));
|
||||
expect(bits).toBeTruthy();
|
||||
expect(bits.reason).toBe("reason here");
|
||||
expect(bits.ruleType).toBe(RULE_ROOM);
|
||||
expect(bits.entity).toBe("!example.org");
|
||||
expect(bits.list).toBeDefined();
|
||||
expect(bits.list.listShortcode).toBe("test");
|
||||
});
|
||||
|
||||
it("should be able to detect room IDs with globs", async () => {
|
||||
const mjolnir = createTestMjolnir();
|
||||
(<any>mjolnir).lists = [{listShortcode: "test"}];
|
||||
@ -147,6 +181,23 @@ describe("UnbanBanCommand", () => {
|
||||
expect(bits.list.listShortcode).toBe("test");
|
||||
});
|
||||
|
||||
it("should be able to detect room aliases with ban reasons", async () => {
|
||||
const mjolnir = createTestMjolnir();
|
||||
(<any>mjolnir).lists = [{listShortcode: "test"}];
|
||||
mjolnir.client.sendMessage = (roomId: string, content: any): Promise<string> => {
|
||||
throw new Error("sendMessage should not have been called: " + JSON.stringify(content));
|
||||
};
|
||||
|
||||
const command = "!mjolnir ban test #example.org reason here";
|
||||
const bits = await parseArguments("!a", createFakeEvent(command), mjolnir, command.split(' '));
|
||||
expect(bits).toBeTruthy();
|
||||
expect(bits.reason).toBe("reason here");
|
||||
expect(bits.ruleType).toBe(RULE_ROOM);
|
||||
expect(bits.entity).toBe("#example.org");
|
||||
expect(bits.list).toBeDefined();
|
||||
expect(bits.list.listShortcode).toBe("test");
|
||||
});
|
||||
|
||||
it("should be able to detect room aliases with globs", async () => {
|
||||
const mjolnir = createTestMjolnir();
|
||||
(<any>mjolnir).lists = [{listShortcode: "test"}];
|
||||
@ -198,6 +249,23 @@ describe("UnbanBanCommand", () => {
|
||||
expect(bits.list.listShortcode).toBe("test");
|
||||
});
|
||||
|
||||
it("should be able to detect user IDs with ban reasons", async () => {
|
||||
const mjolnir = createTestMjolnir();
|
||||
(<any>mjolnir).lists = [{listShortcode: "test"}];
|
||||
mjolnir.client.sendMessage = (roomId: string, content: any): Promise<string> => {
|
||||
throw new Error("sendMessage should not have been called: " + JSON.stringify(content));
|
||||
};
|
||||
|
||||
const command = "!mjolnir ban test @example.org reason here";
|
||||
const bits = await parseArguments("!a", createFakeEvent(command), mjolnir, command.split(' '));
|
||||
expect(bits).toBeTruthy();
|
||||
expect(bits.reason).toBe("reason here");
|
||||
expect(bits.ruleType).toBe(RULE_USER);
|
||||
expect(bits.entity).toBe("@example.org");
|
||||
expect(bits.list).toBeDefined();
|
||||
expect(bits.list.listShortcode).toBe("test");
|
||||
});
|
||||
|
||||
it("should be able to detect user IDs with globs", async () => {
|
||||
const mjolnir = createTestMjolnir();
|
||||
(<any>mjolnir).lists = [{listShortcode: "test"}];
|
||||
|
Loading…
Reference in New Issue
Block a user