commit
Add $ as a no-proxy prefix and move commands to d$
Messages starting with $ are never proxied, by tags or autoproxy. Co-Authored-By: Sandrone <[email protected]>
diff --git a/src/commands/autoproxy.ts b/src/commands/autoproxy.ts
index f5b6f35..6a06713 100644
--- a/src/commands/autoproxy.ts
+++ b/src/commands/autoproxy.ts
@@ -31,7 +31,7 @@ export async function autoproxyCommand(
}
if (choice !== "on" && choice !== "off") {
- await message.reply("Use `d!autoproxy on|off`, or `d!autoproxy -g on|off` for every server.");
+ await message.reply("Use `d$autoproxy on|off`, or `d$autoproxy -g on|off` for every server.");
return;
}
@@ -57,7 +57,7 @@ async function globalAutoproxy(
}
if (choice !== "on" && choice !== "off") {
- await message.reply("Use `d!autoproxy -g on` or `d!autoproxy -g off`.");
+ await message.reply("Use `d$autoproxy -g on` or `d$autoproxy -g off`.");
return;
}
diff --git a/src/commands/help.ts b/src/commands/help.ts
index 5607c24..e341f76 100644
--- a/src/commands/help.ts
+++ b/src/commands/help.ts
@@ -3,11 +3,11 @@
import type { Message } from "discord.js";
const helpText = [
- "`d!edit <text>` edits the message you reply to, or your latest proxied message. `d!e` works too.",
- "`d!explain` explains the bot, and plurality. `d!ex` works too,",
- "`d!autoproxy` shows the state for this server, `d!autoproxy on|off` sets it. Add `-g` for every server, like `d!autoproxy -g off`. `d!ap` works too.",
- "`d!reproxy <member>` resends the message you reply to, or your latest proxied message, as someone else, like `d!reproxy c1`. `d!rp` works too.",
- "`d!switch <member>` sets who's fronting on the site, like `d!switch c1 c2`. `d!switch out` clears it. `d!sw` works too.",
+ "`d$edit <text>` edits the message you reply to, or your latest proxied message. `d$e` works too.",
+ "`d$explain` explains the bot, and plurality. `d$ex` works too,",
+ "`d$autoproxy` shows the state for this server, `d$autoproxy on|off` sets it. Add `-g` for every server, like `d$autoproxy -g off`. `d$ap` works too.",
+ "`d$reproxy <member>` resends the message you reply to, or your latest proxied message, as someone else, like `d$reproxy c1`. `d$rp` works too.",
+ "`d$switch <member>` sets who's fronting on the site, like `d$switch c1 c2`. `d$switch out` clears it. `d$sw` works too.",
"-# React ❌ to delete a proxied message, ❓ to see who sent it.",
].join("\n");
diff --git a/src/commands/index.ts b/src/commands/index.ts
index a0dcd03..d0e836d 100644
--- a/src/commands/index.ts
+++ b/src/commands/index.ts
@@ -37,7 +37,7 @@ export async function runCommand(message: Message): Promise<boolean> {
const handler = commands[parsed.name];
if (!handler) {
- await message.reply(`Unknown command \`${parsed.name}\`. Try \`d!help\`.`);
+ await message.reply(`Unknown command \`${parsed.name}\`. Try \`d$help\`.`);
return true;
}
diff --git a/src/commands/parse.ts b/src/commands/parse.ts
index e85f83f..68666cb 100644
--- a/src/commands/parse.ts
+++ b/src/commands/parse.ts
@@ -1,27 +1,28 @@
/* src/commands/parse.ts */
-export const commandPrefix = "d!";
+export const commandPrefix = "d$";
+export const noProxyPrefix = "$";
export interface ParsedCommand {
- name: string;
- args: string[];
- // Everything after the name, untouched, for commands that take free text
- rest: string;
+ name: string;
+ args: string[];
+ // Everything after the name, untouched, for commands that take free text
+ rest: string;
}
export function parseCommand(content: string): ParsedCommand | null {
- if (!content.toLowerCase().startsWith(commandPrefix)) return null;
+ if (!content.toLowerCase().startsWith(commandPrefix)) return null;
- const body = content.slice(commandPrefix.length).trimStart();
- const name = body.split(/\s/, 1)[0];
+ const body = content.slice(commandPrefix.length).trimStart();
+ const name = body.split(/\s/, 1)[0];
- if (!name) return null;
+ if (!name) return null;
- const rest = body.slice(name.length).trim();
+ const rest = body.slice(name.length).trim();
- return {
- name: name.toLowerCase(),
- args: rest ? rest.toLowerCase().split(/\s+/) : [],
- rest,
- };
+ return {
+ name: name.toLowerCase(),
+ args: rest ? rest.toLowerCase().split(/\s+/) : [],
+ rest,
+ };
}
diff --git a/src/commands/reproxy.ts b/src/commands/reproxy.ts
index 3878bf5..1c80158 100644
--- a/src/commands/reproxy.ts
+++ b/src/commands/reproxy.ts
@@ -11,7 +11,7 @@ export async function reproxyCommand(
args: string[],
): Promise<void> {
if (args.length === 0) {
- await message.reply("Use `d!reproxy <member>`, like `d!reproxy c1`. Several work too: `d!rp c1 c2`.");
+ await message.reply("Use `d$reproxy <member>`, like `d$reproxy c1`. Several work too: `d$rp c1 c2`.");
return;
}
diff --git a/src/commands/switch.ts b/src/commands/switch.ts
index 7c15852..429570c 100644
--- a/src/commands/switch.ts
+++ b/src/commands/switch.ts
@@ -11,7 +11,7 @@ export async function switchCommand(
args: string[],
): Promise<void> {
if (args.length === 0) {
- await message.reply("Use `d!switch <member>`, like `d!switch c1`, several like `d!sw c1 c2`, or `d!sw out`.");
+ await message.reply("Use `d$switch <member>`, like `d$switch c1`, several like `d$sw c1 c2`, or `d$sw out`.");
return;
}
diff --git a/src/config/env.ts b/src/config/env.ts
index 88a4e6f..d0cc102 100644
--- a/src/config/env.ts
+++ b/src/config/env.ts
@@ -10,5 +10,5 @@ if (!token || !ownerId) {
export const discordToken: string = token;
export const ownerUserId: string = ownerId;
-// Optional: without it everything works except d!switch
+// Optional: without it everything works except d$switch
export const siteToken: string | undefined = Deno.env.get("SITE_TOKEN");
diff --git a/src/proxy/autoproxy.ts b/src/proxy/autoproxy.ts
index e992b7f..ce3376d 100644
--- a/src/proxy/autoproxy.ts
+++ b/src/proxy/autoproxy.ts
@@ -1,14 +1,17 @@
/* src/proxy/autoproxy.ts */
+import { noProxyPrefix } from "../commands/parse.ts";
import { matchProxyTags } from "./tags.ts";
import type { Member, ProxyMatch } from "./types.ts";
-// Tags win; otherwise everyone fronting speaks together. A leading "\" skips it
+// A leading "$" never proxies. Tags win; otherwise everyone fronting speaks together. A leading "\" skips that
export function pickProxy(
members: Member[],
fronters: Member[],
content: string,
): ProxyMatch | null {
+ if (content.startsWith(noProxyPrefix)) return null;
+
const tagged = matchProxyTags(members, content);
if (tagged) return tagged;
if (content.startsWith("\\")) return null;
diff --git a/tests/commands/parse_test.ts b/tests/commands/parse_test.ts
index b26fbbf..0e5283a 100644
--- a/tests/commands/parse_test.ts
+++ b/tests/commands/parse_test.ts
@@ -5,7 +5,7 @@ import { assertEquals } from "@std/assert";
import { parseCommand } from "../../src/commands/parse.ts";
Deno.test("parses name and args, case-insensitive", () => {
- assertEquals(parseCommand("D!AutoProxy OFF"), {
+ assertEquals(parseCommand("D$AutoProxy OFF"), {
name: "autoproxy",
args: ["off"],
rest: "OFF",
@@ -13,17 +13,17 @@ Deno.test("parses name and args, case-insensitive", () => {
});
Deno.test("rest keeps the original text for edits", () => {
- assertEquals(parseCommand("d!edit Hello World")?.rest, "Hello World");
+ assertEquals(parseCommand("d$edit Hello World")?.rest, "Hello World");
});
Deno.test("no args gives an empty list", () => {
- assertEquals(parseCommand("d!help")?.args, []);
+ assertEquals(parseCommand("d$help")?.args, []);
});
Deno.test("plain messages are not commands", () => {
- assertEquals(parseCommand("hello d!autoproxy"), null);
+ assertEquals(parseCommand("hello d$autoproxy"), null);
});
Deno.test("bare prefix is not a command", () => {
- assertEquals(parseCommand("d! "), null);
+ assertEquals(parseCommand("d$ "), null);
});
diff --git a/tests/proxy/autoproxy_test.ts b/tests/proxy/autoproxy_test.ts
index 0c25299..69ea638 100644
--- a/tests/proxy/autoproxy_test.ts
+++ b/tests/proxy/autoproxy_test.ts
@@ -35,6 +35,10 @@ Deno.test("backslash skips autoproxy", () => {
assertEquals(pickProxy([], [host], "\\not proxied"), null);
});
+Deno.test("dollar sign skips tags and autoproxy", () => {
+ assertEquals(pickProxy([host], [host], "$not proxied"), null);
+});
+
Deno.test("nobody fronting means no proxy", () => {
assertEquals(pickProxy([], [], "hi"), null);
});