3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

feat: include categorized tags in the tag list command

This commit is contained in:
Ruby 2024-10-25 17:13:58 +02:00
parent eb5fda8d19
commit 1c0b41597c
No known key found for this signature in database
GPG key ID: E0BDFAF7AE9E0531

View file

@ -12,23 +12,20 @@ export const TagListCmd = tagsCmd({
}, },
async run({ message: msg, args, pluginData }) { async run({ message: msg, args, pluginData }) {
const tags = await pluginData.state.tags.all(); const config = await pluginData.config.getForMessage(msg);
if (tags.length === 0) {
msg.channel.send(`No tags created yet! Use \`tag create\` command to create one.`);
return;
}
const prefix = (await pluginData.config.getForMessage(msg)).prefix;
const tagNames = tags.map((tag) => tag.tag).sort();
const searchRegex = args.search const searchRegex = args.search
? new RegExp([...args.search].map((s) => escapeStringRegexp(s)).join(".*"), "i") ? new RegExp([...args.search].map((s) => escapeStringRegexp(s)).join(".*"), "i")
: null; : 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) { if (filteredTags.length === 0) {
msg.channel.send("No tags matched the filter"); return "";
return;
} }
const tagGroups = filteredTags.reduce((obj, tag) => { const tagGroups = filteredTags.reduce((obj, tag) => {
@ -46,6 +43,22 @@ export const TagListCmd = tagsCmd({
.map((key) => `[${key}] ${tagGroups[key].join(", ")}`) .map((key) => `[${key}] ${tagGroups[key].join(", ")}`)
.join("\n"); .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"));
}, },
}); });