3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-14 21:31:50 +00:00

feat: small tweaks to tag list search

This commit is contained in:
Dragory 2022-08-14 00:21:21 +03:00
parent e9fe0e03b9
commit a15b2f02a9
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -1,6 +1,7 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { createChunkedMessage } from "../../../utils";
import { tagsCmd } from "../types";
import escapeStringRegexp from "escape-string-regexp";
export const TagListCmd = tagsCmd({
trigger: ["tag list", "tags", "taglist"],
@ -19,20 +20,16 @@ export const TagListCmd = tagsCmd({
const prefix = (await pluginData.config.getForMessage(msg)).prefix;
const tagNames = tags.map((tag) => tag.tag).sort();
const searchRegex = args.search ? new RegExp([...args.search].map((s) => escapeStringRegexp(s)).join(".*")) : null;
const filteredTags = args.search
? tagNames.filter((tag) =>
new RegExp(
args.search
.split("")
.map((char) => char.replace(/[.*+?^${}()|[\]\\]/, "\\$&"))
.join(".*")
).test(tag)
)
: tagNames;
const filteredTags = args.search ? tagNames.filter((tag) => searchRegex!.test(tag)) : tagNames;
const tagGroups = filteredTags.reduce((acc, tag) => {
const obj = { ...acc };
if (filteredTags.length === 0) {
msg.channel.send("No tags matched the filter");
return;
}
const tagGroups = filteredTags.reduce((obj, tag) => {
const tagUpper = tag.toUpperCase();
const key = /[A-Z]/.test(tagUpper[0]) ? tagUpper[0] : "#";
if (!(key in obj)) {