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

Make Draupnir refer to it self in help output. #358

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/Draupnir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class Draupnir implements Client {
*/
public unlistedUserRedactionQueue = new UnlistedUserRedactionQueue();

private readonly commandTable = findCommandTable("mjolnir");
private readonly commandTable = findCommandTable("draupnir");
public taskQueue: ThrottlingQueue;
/**
* Reporting back to the management room.
Expand Down
4 changes: 2 additions & 2 deletions src/commands/Ban.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async function ban(

defineInterfaceCommand({
designator: ["ban"],
table: "mjolnir",
table: "draupnir",
parameters: parameters([
{
name: "entity",
Expand Down Expand Up @@ -126,6 +126,6 @@ defineInterfaceCommand({
})

defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("mjolnir", "ban"),
interfaceCommand: findTableCommand("draupnir", "ban"),
renderer: tickCrossRenderer
})
4 changes: 2 additions & 2 deletions src/commands/CommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import "./DeactivateCommand";
import "./HijackRoomCommand";
import "./ShutdownRoomCommand";

defineCommandTable("mjolnir").importTable(findCommandTable("synapse admin"));
defineCommandTable("draupnir").importTable(findCommandTable("synapse admin"));
import "./Ban";
import "./CreateBanListCommand";
import "./Help";
Expand Down Expand Up @@ -79,7 +79,7 @@ export async function handleCommand(
const readItems = readCommand(normalisedCommand)
const stream = new ArgumentStream(readItems);
const command = commandTable.findAMatchingCommand(stream)
?? findTableCommand("mjolnir", "help");
?? findTableCommand("draupnir", "help");
const adaptor = findMatrixInterfaceAdaptor(command);
const draupnirContext: DraupnirContext = {
...draupnir.commandContext,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/CreateBanListCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function createList(

defineInterfaceCommand({
designator: ["list", "create"],
table: "mjolnir",
table: "draupnir",
parameters: parameters([
{
name: "shortcode",
Expand All @@ -79,7 +79,7 @@ defineInterfaceCommand({
})

defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("mjolnir", "list", "create"),
interfaceCommand: findTableCommand("draupnir", "list", "create"),
renderer: tickCrossRenderer
})

Expand Down
6 changes: 3 additions & 3 deletions src/commands/Help.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ function renderMjolnirHelp(mjolnirTable: CommandTable): DocumentNode {

defineInterfaceCommand({
parameters: parameters([], new RestDescription('command parts', findPresentationType("any"))),
table: "mjolnir",
table: "draupnir",
command: async function() {
return Ok(findCommandTable("mjolnir"))
return Ok(findCommandTable("draupnir"))
},
designator: ["help"],
summary: "Display this message"
})

defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("mjolnir", "help"),
interfaceCommand: findTableCommand("draupnir", "help"),
renderer: async function(client, commandRoomId, event, result: ActionResult<CommandTable>) {
if (isError(result)) {
throw new TypeError("This command isn't supposed to fail");
Expand Down
4 changes: 2 additions & 2 deletions src/commands/ImportCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function importCommand(

defineInterfaceCommand<DraupnirBaseExecutor>({
designator: ["import"],
table: "mjolnir",
table: "draupnir",
parameters: parameters([
{
name: "import from room",
Expand All @@ -101,6 +101,6 @@ defineInterfaceCommand<DraupnirBaseExecutor>({
})

defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("mjolnir", "import"),
interfaceCommand: findTableCommand("draupnir", "import"),
renderer: tickCrossRenderer
})
4 changes: 2 additions & 2 deletions src/commands/KickCommand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export async function kickCommand(

defineInterfaceCommand({
designator: ["kick"],
table: "mjolnir",
table: "draupnir",
parameters: parameters([
{
name: "user",
Expand Down Expand Up @@ -137,7 +137,7 @@ defineInterfaceCommand({
})

defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("mjolnir", "kick"),
interfaceCommand: findTableCommand("draupnir", "kick"),
renderer: async function (this, client, commandRoomdID, event, result: ActionResult<UsersToKick>) {
tickCrossRenderer.call(this, client, commandRoomdID, event, result);
if (isError(result)) {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/PermissionCheckCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { tickCrossRenderer } from "./interface-manager/MatrixHelpRenderer";

defineInterfaceCommand({
designator: ["verify"],
table: "mjolnir",
table: "draupnir",
parameters: parameters([]),
command: async function (this: DraupnirContext, _keywords: ParsedKeywords): Promise<ActionResult<unknown>> {
const enabledProtection = this.draupnir.protectedRoomsSet.protections.allProtections;
Expand All @@ -53,6 +53,6 @@ defineInterfaceCommand({
})

defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("mjolnir", "verify"),
interfaceCommand: findTableCommand("draupnir", "verify"),
renderer: tickCrossRenderer
})
20 changes: 10 additions & 10 deletions src/commands/ProtectionsCommands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { renderMatrixAndSend } from "./interface-manager/DeadDocumentMatrix";

defineInterfaceCommand({
designator: ["protections", "enable"],
table: "mjolnir",
table: "draupnir",
parameters: parameters([
{
name: 'protection name',
Expand Down Expand Up @@ -75,13 +75,13 @@ defineInterfaceCommand({
})

defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("mjolnir", "protections", "enable"),
interfaceCommand: findTableCommand("draupnir", "protections", "enable"),
renderer: tickCrossRenderer
});

defineInterfaceCommand({
designator: ["protections", "disable"],
table: "mjolnir",
table: "draupnir",
parameters: parameters([
{
name: 'protection name',
Expand All @@ -104,7 +104,7 @@ defineInterfaceCommand({
})

defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("mjolnir", "protections", "disable"),
interfaceCommand: findTableCommand("draupnir", "protections", "disable"),
renderer: tickCrossRenderer
});

Expand All @@ -127,7 +127,7 @@ interface SettingChangeSummary<Key extends string = string, TSettings extends Un

defineInterfaceCommand({
designator: ["protections", "config", "set"],
table: "mjolnir",
table: "draupnir",
parameters: parameters([...CommonProtectionSettingParameters, {
name: 'new value',
acceptor: findPresentationType('any'),
Expand Down Expand Up @@ -156,7 +156,7 @@ defineInterfaceCommand({

defineInterfaceCommand({
designator: ["protections", "config", "add"],
table: "mjolnir",
table: "draupnir",
parameters: parameters([
{
name: 'item',
Expand Down Expand Up @@ -192,7 +192,7 @@ defineInterfaceCommand({

defineInterfaceCommand({
designator: ["protections", "config", "remove"],
table: "mjolnir",
table: "draupnir",
parameters: parameters([
{
name: 'item',
Expand Down Expand Up @@ -251,7 +251,7 @@ async function settingChangeSummaryRenderer(this: unknown, client: MatrixSendCli

for (const designator of ["add", "set", "remove"]) {
defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("mjolnir", "protections", "config", designator),
interfaceCommand: findTableCommand("draupnir", "protections", "config", designator),
renderer: settingChangeSummaryRenderer,
})
}
Expand Down Expand Up @@ -331,7 +331,7 @@ interface ProtectionsSummary {

defineInterfaceCommand({
designator: ["protections"],
table: "mjolnir",
table: "draupnir",
parameters: parameters([]),
command: async function (this: DraupnirContext, keywords: ParsedKeywords, protectionName: string): Promise<ActionResult<ProtectionsSummary[]>> {
const enabledProtections = this.draupnir.protectedRoomsSet.protections.allProtections;
Expand All @@ -357,7 +357,7 @@ defineInterfaceCommand({
})

defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("mjolnir", "protections"),
interfaceCommand: findTableCommand("draupnir", "protections"),
renderer: async function(client, commandRoomID, event, result: ActionResult<ProtectionsSummary[]>) {
await tickCrossRenderer.call(this, client, commandRoomID, event, result);
if (isError(result)) {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/RedactCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export async function redactCommand(

defineInterfaceCommand({
designator: ["redact"],
table: "mjolnir",
table: "draupnir",
parameters: parameters([
{
name: "entity",
Expand Down Expand Up @@ -117,6 +117,6 @@ defineInterfaceCommand({
});

defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("mjolnir", "redact"),
interfaceCommand: findTableCommand("draupnir", "redact"),
renderer: tickCrossRenderer
})
4 changes: 2 additions & 2 deletions src/commands/ResolveAlias.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async function resolveAliasCommand(
}

defineInterfaceCommand({
table: "mjolnir",
table: "draupnir",
designator: ["resolve"],
parameters: parameters([{
name: "alias",
Expand All @@ -55,7 +55,7 @@ defineInterfaceCommand({
})

defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("mjolnir", "resolve"),
interfaceCommand: findTableCommand("draupnir", "resolve"),
renderer: async function(this, client, commandRoomID, event, result: ActionResult<MatrixRoomID>) {
if (isError(result)) {
await tickCrossRenderer.call(this, client, commandRoomID, event, result);
Expand Down
10 changes: 5 additions & 5 deletions src/commands/Rooms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { ActionException, ActionExceptionKind, ActionResult, MatrixRoomID, Matri
import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk";

defineInterfaceCommand({
table: "mjolnir",
table: "draupnir",
designator: ["rooms"],
summary: "List all of the protected rooms.",
parameters: parameters([]),
Expand All @@ -58,7 +58,7 @@ function renderProtectedRooms(rooms: MatrixRoomID[]): DocumentNode {
}

defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("mjolnir", "rooms"),
interfaceCommand: findTableCommand("draupnir", "rooms"),
renderer: async function (client, commandRoomId, event, result: ActionResult<MatrixRoomID[]>) {
tickCrossRenderer.call(this, ...arguments);
if (isError(result)) {
Expand All @@ -72,7 +72,7 @@ defineMatrixInterfaceAdaptor({
})

defineInterfaceCommand({
table: "mjolnir",
table: "draupnir",
designator: ["rooms", "add"],
summary: "Protect the room using the watched policy lists, banning users and synchronizing server ACL.",
parameters: parameters([
Expand All @@ -96,7 +96,7 @@ defineInterfaceCommand({
})

defineInterfaceCommand({
table: "mjolnir",
table: "draupnir",
designator: ["rooms", "remove"],
summary: "Stop protecting the room and leave.",
parameters: parameters([
Expand Down Expand Up @@ -132,7 +132,7 @@ defineInterfaceCommand({

for (const designator of [["rooms", "add"], ["rooms", "remove"]]) {
defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("mjolnir", ...designator),
interfaceCommand: findTableCommand("draupnir", ...designator),
renderer: tickCrossRenderer,
})
}
8 changes: 4 additions & 4 deletions src/commands/Rules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export interface ListMatches {

defineInterfaceCommand({
designator: ["rules"],
table: "mjolnir",
table: "draupnir",
parameters: parameters([]),
command: async function (this: DraupnirContext): Promise<ActionResult<ListMatches[]>> {
const infoResult = await listInfo(this.draupnir);
Expand All @@ -102,13 +102,13 @@ defineInterfaceCommand({
})

defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("mjolnir", "rules"),
interfaceCommand: findTableCommand("draupnir", "rules"),
renderer: renderListMatches
})

defineInterfaceCommand({
designator: ["rules", "matching"],
table: "mjolnir",
table: "draupnir",
parameters: parameters([
{
name: "entity",
Expand Down Expand Up @@ -140,6 +140,6 @@ defineInterfaceCommand({

// I'm pretty sure that both commands could merge and use the same rendeer.
defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("mjolnir", "rules", "matching"),
interfaceCommand: findTableCommand("draupnir", "rules", "matching"),
renderer: renderListMatches
})
4 changes: 2 additions & 2 deletions src/commands/SetDisplayNameCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ActionError, ActionResult, Ok } from "matrix-protection-suite";


defineInterfaceCommand({
table: "mjolnir",
table: "draupnir",
designator: ["displayname"],
summary: "Sets the displayname of the draupnir instance to the specified value in all rooms.",
parameters: parameters(
Expand All @@ -34,6 +34,6 @@ export async function execSetDisplayNameCommand(this: DraupnirContext, _keywords
}

defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("mjolnir", "displayname"),
interfaceCommand: findTableCommand("draupnir", "displayname"),
renderer: tickCrossRenderer
})
2 changes: 1 addition & 1 deletion src/commands/SetPowerLevelCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async function setPowerLevelCommand(
}

defineInterfaceCommand({
table: "mjolnir",
table: "draupnir",
designator: ["powerlevel"],
parameters: parameters([
{
Expand Down
4 changes: 2 additions & 2 deletions src/commands/StatusCommand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { DocumentNode } from "./interface-manager/DeadDocument";

defineInterfaceCommand({
designator: ["status"],
table: "mjolnir",
table: "draupnir",
parameters: parameters([]),
command: async function (this: DraupnirContext): Promise<ActionResult<StatusInfo>> {
return Ok(await draupnirStatusInfo(this.draupnir))
Expand Down Expand Up @@ -121,7 +121,7 @@ export function renderStatusInfo(info: StatusInfo): DocumentNode {
}

defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("mjolnir", "status"),
interfaceCommand: findTableCommand("draupnir", "status"),
renderer: async function (this, client, commandRoomID, event, result: ActionResult<StatusInfo>): Promise<void> {
if (isError(result)) {
await tickCrossRenderer.call(this, client, commandRoomID, event, result);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/Unban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async function unban(

defineInterfaceCommand({
designator: ["unban"],
table: "mjolnir",
table: "draupnir",
parameters: parameters([
{
name: "entity",
Expand Down Expand Up @@ -150,6 +150,6 @@ defineInterfaceCommand({
})

defineMatrixInterfaceAdaptor({
interfaceCommand: findTableCommand("mjolnir", "unban"),
interfaceCommand: findTableCommand("draupnir", "unban"),
renderer: tickCrossRenderer
})
Loading
Loading