feat: slash commands with autocomplete dropdown
Type / at start of message to see available commands. Commands: /shrug, /tableflip, /unflip, /lenny, /bear, /disapprove, /facepalm, /cry, /dance, /hug, /greet, /me (action text), /spoiler (hidden text). Autocomplete dropdown with tab-complete. Commands transform input text client-side before sending. Unknown /commands pass through as regular messages.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
export interface SlashCommand {
|
||||
name: string;
|
||||
description: string;
|
||||
transform: (args: string, username: string) => string;
|
||||
}
|
||||
|
||||
const SHRUG = '\u00AF\\_(\u30C4)_/\u00AF';
|
||||
const TABLEFLIP = '(\u256F\u00B0\u25A1\u00B0\uFF09\u256F\uFE35 \u253B\u2501\u253B';
|
||||
const UNFLIP = '\u252C\u2500\u252C\u30CE( \u00BA _ \u00BA\u30CE)';
|
||||
const LENNY = '( \u0361\u00B0 \u035C\u0325 \u0361\u00B0)';
|
||||
const BEAR = '\u0295\u2022\u1D25\u2022\u0294';
|
||||
const DISAPPROVE = '\u0CA0_\u0CA0';
|
||||
const FACEPALM = '(\uFF0D\u1DD9\uFF4D)';
|
||||
const CRY = '(\u2568_\u2568)';
|
||||
const DANCE = '\u250C(\u30FB\u30FB\u30FB)\u2518\u266A';
|
||||
const HUG = '(\u2283\u301C\u203F\u2022\u032F\u2022\uFF65\u0300)\u2283';
|
||||
const GREET = '(\u30CE\u00B4\uFF89`)\u30CE';
|
||||
|
||||
function appendOrReturn(kaomoji: string, args: string): string {
|
||||
return args ? args + ' ' + kaomoji : kaomoji;
|
||||
}
|
||||
|
||||
export const SLASH_COMMANDS: SlashCommand[] = [
|
||||
{ name: 'shrug', description: 'Append shrug kaomoji', transform: (a) => appendOrReturn(SHRUG, a) },
|
||||
{ name: 'tableflip', description: 'Flip a table', transform: (a) => appendOrReturn(TABLEFLIP, a) },
|
||||
{ name: 'unflip', description: 'Put the table back', transform: (a) => appendOrReturn(UNFLIP, a) },
|
||||
{ name: 'lenny', description: '( \u0361\u00B0 \u035C\u0325 \u0361\u00B0)', transform: (a) => appendOrReturn(LENNY, a) },
|
||||
{ name: 'bear', description: 'Kaomoji bear', transform: (a) => a ? BEAR + ' ' + a : BEAR },
|
||||
{ name: 'disapprove', description: 'Look of disapproval', transform: (a) => appendOrReturn(DISAPPROVE, a) },
|
||||
{ name: 'facepalm', description: 'Facepalm', transform: (a) => appendOrReturn(FACEPALM, a) },
|
||||
{ name: 'cry', description: 'Crying', transform: (a) => appendOrReturn(CRY, a) },
|
||||
{ name: 'dance', description: 'Dance', transform: (a) => appendOrReturn(DANCE, a) },
|
||||
{ name: 'hug', description: 'Hug', transform: (a) => a ? HUG + ' ' + a : HUG },
|
||||
{ name: 'greet', description: 'Friendly wave hello', transform: (a) => a ? GREET + ' ' + a : GREET + ' Hello!' },
|
||||
{ name: 'me', description: 'Send an action message', transform: (a, u) => '*' + u + ' ' + a + '*' },
|
||||
{ name: 'spoiler', description: 'Hide text as a spoiler', transform: (a) => '||' + a + '||' },
|
||||
];
|
||||
|
||||
export function findCommand(name: string): SlashCommand | undefined {
|
||||
return SLASH_COMMANDS.find((c) => c.name === name.toLowerCase());
|
||||
}
|
||||
|
||||
export function matchingCommands(query: string): SlashCommand[] {
|
||||
const q = query.toLowerCase();
|
||||
return SLASH_COMMANDS.filter((c) => c.name.startsWith(q));
|
||||
}
|
||||
Reference in New Issue
Block a user