mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-25 18:25:03 +00:00
add command for listing tag aliases by tag, add flag to not show aliases when listing tags
This commit is contained in:
parent
e39c66dbc9
commit
af4c027891
4 changed files with 57 additions and 8 deletions
|
@ -16,6 +16,7 @@ import { TagCreateCmd } from "./commands/TagCreateCmd";
|
|||
import { TagDeleteCmd } from "./commands/TagDeleteCmd";
|
||||
import { TagEvalCmd } from "./commands/TagEvalCmd";
|
||||
import { TagListCmd } from "./commands/TagListCmd";
|
||||
import { TagListAliasesCmd } from "./commands/TagListAliasesCmd";
|
||||
import { TagSourceCmd } from "./commands/TagSourceCmd";
|
||||
import { ConfigSchema, TagsPluginType } from "./types";
|
||||
import { findTagByName } from "./util/findTagByName";
|
||||
|
@ -69,7 +70,7 @@ export const TagsPlugin = zeppelinGuildPlugin<TagsPluginType>()({
|
|||
You use them by adding a \`{}\` on your tag.
|
||||
|
||||
Here are the functions you can use in your tags:
|
||||
|
||||
|
||||
${generateTemplateMarkdown(TemplateFunctions)}
|
||||
`),
|
||||
},
|
||||
|
@ -83,6 +84,7 @@ export const TagsPlugin = zeppelinGuildPlugin<TagsPluginType>()({
|
|||
TagEvalCmd,
|
||||
TagDeleteCmd,
|
||||
TagListCmd,
|
||||
TagListAliasesCmd,
|
||||
TagSourceCmd,
|
||||
TagCreateCmd,
|
||||
],
|
||||
|
|
28
backend/src/plugins/Tags/commands/TagListAliasesCmd.ts
Normal file
28
backend/src/plugins/Tags/commands/TagListAliasesCmd.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { createChunkedMessage } from "../../../utils";
|
||||
import { tagsCmd } from "../types";
|
||||
|
||||
export const TagListAliasesCmd = tagsCmd({
|
||||
trigger: ["tag list-aliases", "tagaliases"],
|
||||
permission: "can_list",
|
||||
|
||||
signature: {
|
||||
tag: ct.string(),
|
||||
},
|
||||
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
const prefix = (await pluginData.config.getForMessage(msg)).prefix;
|
||||
const aliases = await pluginData.state.tagAliases.findAllWithTag(args.tag);
|
||||
let aliasesArr: string[] = [];
|
||||
if (!aliases) {
|
||||
msg.channel.send(`No aliases found for tag \`${args.tag}\``);
|
||||
return;
|
||||
}
|
||||
aliasesArr = aliases.map((a) => a.alias);
|
||||
createChunkedMessage(
|
||||
msg.channel,
|
||||
`Available aliases for tag \`${prefix + args.tag}\`: \`\`\`${aliasesArr.join(", ")}\`\`\``,
|
||||
);
|
||||
return;
|
||||
},
|
||||
});
|
|
@ -1,3 +1,4 @@
|
|||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { createChunkedMessage } from "../../../utils";
|
||||
import { tagsCmd } from "../types";
|
||||
|
||||
|
@ -5,7 +6,12 @@ export const TagListCmd = tagsCmd({
|
|||
trigger: ["tag list", "tags", "taglist"],
|
||||
permission: "can_list",
|
||||
|
||||
async run({ message: msg, pluginData }) {
|
||||
signature: {
|
||||
noaliases: ct.bool({ option: true, isSwitch: true, shortcut: "na" }),
|
||||
},
|
||||
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
const prefix = (await pluginData.config.getForMessage(msg)).prefix;
|
||||
const tags = await pluginData.state.tags.all();
|
||||
const aliases = await pluginData.state.tagAliases.all();
|
||||
if (tags.length === 0) {
|
||||
|
@ -13,12 +19,11 @@ export const TagListCmd = tagsCmd({
|
|||
return;
|
||||
}
|
||||
|
||||
const prefix = (await pluginData.config.getForMessage(msg)).prefix;
|
||||
const tagNames = tags.map((tag) => tag.tag).sort();
|
||||
const tagAliasesNames = aliases.map((alias) => alias.alias).sort();
|
||||
const tagAndAliasesNames = tagNames
|
||||
.join(", ")
|
||||
.concat(tagAliasesNames.length > 0 ? `, ${tagAliasesNames.join(", ")}` : "");
|
||||
.concat(args.noaliases ? "" : tagAliasesNames.length > 0 ? `, ${tagAliasesNames.join(", ")}` : "");
|
||||
|
||||
createChunkedMessage(msg.channel, `Available tags (use with ${prefix}tag): \`\`\`${tagAndAliasesNames}\`\`\``);
|
||||
},
|
||||
|
|
|
@ -15,27 +15,41 @@ export const TagSourceCmd = tagsCmd({
|
|||
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
const alias = await pluginData.state.tagAliases.find(args.tag);
|
||||
const tag = (await pluginData.state.tags.find(args.tag)) || (await pluginData.state.tags.find(alias?.tag ?? null));
|
||||
const aliasedTag = await pluginData.state.tags.find(alias?.tag ?? null);
|
||||
const tag = (await pluginData.state.tags.find(args.tag)) || aliasedTag;
|
||||
|
||||
if (args.delete) {
|
||||
const actualTag = await pluginData.state.tags.find(args.tag);
|
||||
const aliasedTag = await pluginData.state.tags.find(alias?.tag ?? null);
|
||||
|
||||
if (!actualTag && !aliasedTag) {
|
||||
sendErrorMessage(pluginData, msg.channel, "No tag with that name");
|
||||
return;
|
||||
}
|
||||
|
||||
actualTag ? pluginData.state.tags.delete(args.tag) : pluginData.state.tagAliases.delete(args.tag);
|
||||
if (actualTag) {
|
||||
const aliasesOfTag = await pluginData.state.tagAliases.findAllWithTag(actualTag?.tag);
|
||||
if (aliasesOfTag) {
|
||||
// tslint:disable-next-line:no-shadowed-variable
|
||||
aliasesOfTag.forEach((alias) => pluginData.state.tagAliases.delete(alias.alias));
|
||||
}
|
||||
await pluginData.state.tags.delete(args.tag);
|
||||
} else {
|
||||
await pluginData.state.tagAliases.delete(alias?.alias);
|
||||
}
|
||||
|
||||
sendSuccessMessage(pluginData, msg.channel, `${actualTag ? "Tag" : "Alias"} deleted!`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!tag) {
|
||||
if (!tag && !aliasedTag) {
|
||||
sendErrorMessage(pluginData, msg.channel, "No tag with that name");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!tag?.body) {
|
||||
return;
|
||||
}
|
||||
|
||||
const archiveId = await pluginData.state.archives.create(tag.body, moment.utc().add(10, "minutes"));
|
||||
const url = pluginData.state.archives.getUrl(getBaseUrl(pluginData), archiveId);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue