mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
Merge pull request #348 from DenverCoderOne/tag-list-search
feat: Tag list search and improved readability
This commit is contained in:
commit
e9fe0e03b9
1 changed files with 34 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||||
import { createChunkedMessage } from "../../../utils";
|
import { createChunkedMessage } from "../../../utils";
|
||||||
import { tagsCmd } from "../types";
|
import { tagsCmd } from "../types";
|
||||||
|
|
||||||
|
@ -5,7 +6,11 @@ export const TagListCmd = tagsCmd({
|
||||||
trigger: ["tag list", "tags", "taglist"],
|
trigger: ["tag list", "tags", "taglist"],
|
||||||
permission: "can_list",
|
permission: "can_list",
|
||||||
|
|
||||||
async run({ message: msg, pluginData }) {
|
signature: {
|
||||||
|
search: ct.string({ required: false }),
|
||||||
|
},
|
||||||
|
|
||||||
|
async run({ message: msg, args, pluginData }) {
|
||||||
const tags = await pluginData.state.tags.all();
|
const tags = await pluginData.state.tags.all();
|
||||||
if (tags.length === 0) {
|
if (tags.length === 0) {
|
||||||
msg.channel.send(`No tags created yet! Use \`tag create\` command to create one.`);
|
msg.channel.send(`No tags created yet! Use \`tag create\` command to create one.`);
|
||||||
|
@ -15,6 +20,33 @@ 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();
|
||||||
|
|
||||||
createChunkedMessage(msg.channel, `Available tags (use with ${prefix}tag): \`\`\`${tagNames.join(", ")}\`\`\``);
|
const filteredTags = args.search
|
||||||
|
? tagNames.filter((tag) =>
|
||||||
|
new RegExp(
|
||||||
|
args.search
|
||||||
|
.split("")
|
||||||
|
.map((char) => char.replace(/[.*+?^${}()|[\]\\]/, "\\$&"))
|
||||||
|
.join(".*")
|
||||||
|
).test(tag)
|
||||||
|
)
|
||||||
|
: tagNames;
|
||||||
|
|
||||||
|
const tagGroups = filteredTags.reduce((acc, tag) => {
|
||||||
|
const obj = { ...acc };
|
||||||
|
const tagUpper = tag.toUpperCase();
|
||||||
|
const key = /[A-Z]/.test(tagUpper[0]) ? tagUpper[0] : "#";
|
||||||
|
if (!(key in obj)) {
|
||||||
|
obj[key] = [];
|
||||||
|
}
|
||||||
|
obj[key].push(tag);
|
||||||
|
return obj;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
const tagList = Object.keys(tagGroups)
|
||||||
|
.sort()
|
||||||
|
.map((key) => `[${key}] ${tagGroups[key].join(", ")}`)
|
||||||
|
.join("\n");
|
||||||
|
|
||||||
|
createChunkedMessage(msg.channel, `Available tags (use with ${prefix}tag): \`\`\`${tagList}\`\`\``);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue