-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #404 from the-draupnir-project/gnuxie/ban-command-…
- Loading branch information
Showing
9 changed files
with
98 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-FileCopyrightText: 2024 Gnuxie <[email protected]> | ||
// | ||
// SPDX-License-Identifier: AFL-3.0 | ||
|
||
import { MatrixEventViaAlias, MatrixEventViaRoomID, MatrixRoomAlias, MatrixRoomID, Permalinks, UserID } from "matrix-protection-suite"; | ||
import { ReadItem } from "./CommandReader"; | ||
|
||
export function printReadably(item: ReadItem): string { | ||
if (item instanceof MatrixRoomID || item instanceof MatrixRoomAlias) { | ||
return item.toPermalink(); | ||
} else if (item instanceof UserID) { | ||
return item.toString(); | ||
} else if (item instanceof MatrixEventViaAlias || item instanceof MatrixEventViaRoomID) { | ||
return Permalinks.forEvent(item.reference.toRoomIDOrAlias(), item.eventID, item.reference.getViaServers()); | ||
} else { | ||
return item.toString() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Ok, isError } from "matrix-protection-suite"; | ||
import { defineCommandTable, defineInterfaceCommand, findTableCommand } from "../../src/commands/interface-manager/InterfaceCommand"; | ||
import { ArgumentStream, findPresentationType, parameters, union } from "../../src/commands/interface-manager/ParameterParsing"; | ||
import { readCommand } from "../../src/commands/interface-manager/CommandReader"; | ||
import "../../src/commands/interface-manager/MatrixPresentations"; | ||
|
||
it('A command that fookin parses mxids', async function() { | ||
const tableName = Symbol("ParseTest"); | ||
defineCommandTable(tableName); | ||
defineInterfaceCommand({ | ||
designator: ["unban"], | ||
table: tableName, | ||
parameters: parameters([ | ||
{ | ||
name: "entity", | ||
acceptor: union( | ||
findPresentationType("UserID"), | ||
findPresentationType("MatrixRoomReference"), | ||
findPresentationType("string") | ||
) | ||
} | ||
], | ||
undefined, | ||
), | ||
command: async function() { | ||
return Ok(undefined); | ||
}, | ||
summary: "Mimicks the unban command" | ||
}); | ||
const command = findTableCommand(tableName, "unban"); | ||
if (command === undefined) { | ||
throw new TypeError(`Command table has gone missing this asin't good guys`); | ||
} | ||
const result = await command.parseThenInvoke(undefined, new ArgumentStream(readCommand("@spam:example.com"))); | ||
if (isError(result)) { | ||
throw new TypeError(`Not supposed to be error mate`); | ||
} | ||
}) |