Invert the purpose of the `-` argument.

Also, increase the extensibility of the formatter by using CCBot's formatting system.
This commit is contained in:
Keanu Timmermans 2021-07-25 20:05:11 +02:00
parent fb2335dda5
commit 7f719912b2
Signed by: keanucode
GPG Key ID: A7431C0D513CA93B
2 changed files with 32 additions and 15 deletions

View File

@ -9,7 +9,7 @@ export default new NamedCommand({
description: "The emote(s) to send.",
usage: "<emotes...>",
async run({send, args}) {
const output = processEmoteQuery(args, true).join("");
const output = processEmoteQuery(args, true);
if (output.length > 0) send(output);
}
})

View File

@ -93,20 +93,37 @@ export function searchNearestEmote(query: string, additionalEmotes?: GuildEmoji[
return "❓";
}
export function processEmoteQuery(query: string[], isFormatted: boolean): string[] {
return query.map((emote) => {
emote = emote.trim();
// If the query directly matches a Unicode emoji or a Discord custom emote mention, pass it as-is.
if (discordEmoteMentionRegex.test(emote) || unicodeEmojiRegex.test(emote)) return emote;
// If formatted mode is enabled, parse whitespace and newline elements.
// This formatting system was blatantly ripped from CCBot.
// <https://github.com/CCDirectLink/ccbot/blob/5b8aa0dbff012a35dc9a54e10b93a397edf6403d/src/commands/emotes.ts#L117-L141>
export function processEmoteQuery(query: string[], isFormatted: boolean): string {
let text = "";
let separator = "";
for (let i = 0; i < query.length; i++) {
const emoteArg: string = query[i];
if (isFormatted) {
if (emote == "-") return " ";
if (emote == "+") return "\n";
if (emote == "_") return "\u200b";
switch (emoteArg) {
case "-": {
separator = "";
break;
}
case "+": {
separator = "\n";
break;
}
case "_": {
separator = "\u200b";
break;
}
default: {
const emote = searchNearestEmote(emoteArg);
if (text.length > 0) text += separator;
text += emote.toString();
separator = " ";
}
}
} else {
text = searchNearestEmote(emoteArg);
}
return searchNearestEmote(emote);
});
}
return text;
}