mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
feat: small tweaks to tag list search
This commit is contained in:
parent
e9fe0e03b9
commit
a15b2f02a9
1 changed files with 9 additions and 12 deletions
|
@ -1,6 +1,7 @@
|
||||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||||
import { createChunkedMessage } from "../../../utils";
|
import { createChunkedMessage } from "../../../utils";
|
||||||
import { tagsCmd } from "../types";
|
import { tagsCmd } from "../types";
|
||||||
|
import escapeStringRegexp from "escape-string-regexp";
|
||||||
|
|
||||||
export const TagListCmd = tagsCmd({
|
export const TagListCmd = tagsCmd({
|
||||||
trigger: ["tag list", "tags", "taglist"],
|
trigger: ["tag list", "tags", "taglist"],
|
||||||
|
@ -19,20 +20,16 @@ export const TagListCmd = tagsCmd({
|
||||||
|
|
||||||
const prefix = (await pluginData.config.getForMessage(msg)).prefix;
|
const prefix = (await pluginData.config.getForMessage(msg)).prefix;
|
||||||
const tagNames = tags.map((tag) => tag.tag).sort();
|
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
|
const filteredTags = args.search ? tagNames.filter((tag) => searchRegex!.test(tag)) : tagNames;
|
||||||
? tagNames.filter((tag) =>
|
|
||||||
new RegExp(
|
|
||||||
args.search
|
|
||||||
.split("")
|
|
||||||
.map((char) => char.replace(/[.*+?^${}()|[\]\\]/, "\\$&"))
|
|
||||||
.join(".*")
|
|
||||||
).test(tag)
|
|
||||||
)
|
|
||||||
: tagNames;
|
|
||||||
|
|
||||||
const tagGroups = filteredTags.reduce((acc, tag) => {
|
if (filteredTags.length === 0) {
|
||||||
const obj = { ...acc };
|
msg.channel.send("No tags matched the filter");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const tagGroups = filteredTags.reduce((obj, tag) => {
|
||||||
const tagUpper = tag.toUpperCase();
|
const tagUpper = tag.toUpperCase();
|
||||||
const key = /[A-Z]/.test(tagUpper[0]) ? tagUpper[0] : "#";
|
const key = /[A-Z]/.test(tagUpper[0]) ? tagUpper[0] : "#";
|
||||||
if (!(key in obj)) {
|
if (!(key in obj)) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue