mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-14 21:31:50 +00:00
feat: include categorized tags in the tag list command
This commit is contained in:
parent
eb5fda8d19
commit
1c0b41597c
1 changed files with 40 additions and 27 deletions
|
@ -12,23 +12,20 @@ export const TagListCmd = tagsCmd({
|
|||
},
|
||||
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
const tags = await pluginData.state.tags.all();
|
||||
if (tags.length === 0) {
|
||||
msg.channel.send(`No tags created yet! Use \`tag create\` command to create one.`);
|
||||
return;
|
||||
}
|
||||
const config = await pluginData.config.getForMessage(msg);
|
||||
|
||||
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(".*"), "i")
|
||||
: null;
|
||||
|
||||
const filteredTags = args.search ? tagNames.filter((tag) => searchRegex!.test(tag)) : tagNames;
|
||||
const messageBody = (prefix = config.prefix, tagNames: string[], category?): string => {
|
||||
if (tagNames.length == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const filteredTags = args.search ? tagNames.filter((tag) => searchRegex!.test(tag)) : tagNames;
|
||||
if (filteredTags.length === 0) {
|
||||
msg.channel.send("No tags matched the filter");
|
||||
return;
|
||||
return "";
|
||||
}
|
||||
|
||||
const tagGroups = filteredTags.reduce((obj, tag) => {
|
||||
|
@ -46,6 +43,22 @@ export const TagListCmd = tagsCmd({
|
|||
.map((key) => `[${key}] ${tagGroups[key].join(", ")}`)
|
||||
.join("\n");
|
||||
|
||||
createChunkedMessage(msg.channel, `Available tags (use with ${prefix}tag): \`\`\`${tagList}\`\`\``);
|
||||
return `Available ${
|
||||
category ? `\`${category}\`` : "uncategorized"
|
||||
} tags (use with ${prefix}tag): \`\`\`${tagList}\`\`\``;
|
||||
};
|
||||
|
||||
const dynamicTags = (await pluginData.state.tags.all()).map((tag) => tag.tag).sort();
|
||||
const dynamicMessageBody = messageBody(config.prefix, dynamicTags);
|
||||
|
||||
const messageBodies = [dynamicMessageBody];
|
||||
|
||||
const tagCategories = Object.entries(config.categories);
|
||||
for (const [category, value] of tagCategories) {
|
||||
const tags = Object.keys(value.tags);
|
||||
messageBodies.push(messageBody(value.prefix ?? config.prefix, tags, category));
|
||||
}
|
||||
|
||||
createChunkedMessage(msg.channel, messageBodies.filter((str) => str.length > 0).join("\n"));
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue