mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-25 10:25:01 +00:00
transfered code from TagListAliasesCmd
into TagListCmd
and
refactored `TagListCmd`
This commit is contained in:
parent
015a908128
commit
ee53e2ddd0
4 changed files with 42 additions and 33 deletions
|
@ -16,7 +16,6 @@ import { TagCreateCmd } from "./commands/TagCreateCmd";
|
||||||
import { TagDeleteCmd } from "./commands/TagDeleteCmd";
|
import { TagDeleteCmd } from "./commands/TagDeleteCmd";
|
||||||
import { TagEvalCmd } from "./commands/TagEvalCmd";
|
import { TagEvalCmd } from "./commands/TagEvalCmd";
|
||||||
import { TagListCmd } from "./commands/TagListCmd";
|
import { TagListCmd } from "./commands/TagListCmd";
|
||||||
import { TagListAliasesCmd } from "./commands/TagListAliasesCmd";
|
|
||||||
import { TagSourceCmd } from "./commands/TagSourceCmd";
|
import { TagSourceCmd } from "./commands/TagSourceCmd";
|
||||||
import { ConfigSchema, TagsPluginType } from "./types";
|
import { ConfigSchema, TagsPluginType } from "./types";
|
||||||
import { findTagByName } from "./util/findTagByName";
|
import { findTagByName } from "./util/findTagByName";
|
||||||
|
@ -84,7 +83,6 @@ export const TagsPlugin = zeppelinGuildPlugin<TagsPluginType>()({
|
||||||
TagEvalCmd,
|
TagEvalCmd,
|
||||||
TagDeleteCmd,
|
TagDeleteCmd,
|
||||||
TagListCmd,
|
TagListCmd,
|
||||||
TagListAliasesCmd,
|
|
||||||
TagSourceCmd,
|
TagSourceCmd,
|
||||||
TagCreateCmd,
|
TagCreateCmd,
|
||||||
],
|
],
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
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 \`${args.tag}\` (use with \`${prefix}alias\`: \`\`\`${aliasesArr.join(", ")}\`\`\``,
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
},
|
|
||||||
});
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { sendErrorMessage } from "src/pluginUtils";
|
||||||
|
|
||||||
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";
|
||||||
|
@ -8,23 +10,59 @@ export const TagListCmd = tagsCmd({
|
||||||
|
|
||||||
signature: {
|
signature: {
|
||||||
noaliases: ct.bool({ option: true, isSwitch: true, shortcut: "na" }),
|
noaliases: ct.bool({ option: true, isSwitch: true, shortcut: "na" }),
|
||||||
|
aliasesonly: ct.bool({ option: true, isSwitch: true, shortcut: "ao" }),
|
||||||
|
tag: ct.string({ option: true }),
|
||||||
},
|
},
|
||||||
|
|
||||||
async run({ message: msg, args, pluginData }) {
|
async run({ message: msg, args, pluginData }) {
|
||||||
const prefix = (await pluginData.config.getForMessage(msg)).prefix;
|
const prefix = (await pluginData.config.getForMessage(msg)).prefix;
|
||||||
const tags = await pluginData.state.tags.all();
|
const tags = await pluginData.state.tags.all();
|
||||||
const aliases = await pluginData.state.tagAliases.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.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const allAliases = await pluginData.state.tagAliases.all();
|
||||||
|
|
||||||
|
if (args.aliasesonly) {
|
||||||
|
let aliasesArr: string[] = [];
|
||||||
|
if (args.tag) {
|
||||||
|
const tag = await pluginData.state.tags.find(args.tag);
|
||||||
|
if (!tag) {
|
||||||
|
sendErrorMessage(pluginData, msg.channel, `Tag \`${args.tag}\` doesn't exist.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const aliasesForTag = await pluginData.state.tagAliases.findAllWithTag(args.tag);
|
||||||
|
if (!aliasesForTag) {
|
||||||
|
sendErrorMessage(pluginData, msg.channel, `No aliases for tag \`${args.tag}\`.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
aliasesArr = aliasesForTag.map((a) => a.alias);
|
||||||
|
createChunkedMessage(
|
||||||
|
msg.channel,
|
||||||
|
`Available aliases for tag \`${args.tag}\` (use with \`${prefix}alias\`: \`\`\`${aliasesArr.join(
|
||||||
|
", ",
|
||||||
|
)}\`\`\``,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
aliasesArr = allAliases.map((a) => a.alias);
|
||||||
|
createChunkedMessage(
|
||||||
|
msg.channel,
|
||||||
|
`Available aliases (use with \`${prefix}alias\`: \`\`\`${aliasesArr.join(", ")}\`\`\``,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const tagNames = tags.map((tag) => tag.tag).sort();
|
const tagNames = tags.map((tag) => tag.tag).sort();
|
||||||
const tagAliasesNames = aliases.map((alias) => alias.alias).sort();
|
const tagAliasesNames = allAliases.map((alias) => alias.alias).sort();
|
||||||
const tagAndAliasesNames = tagNames
|
const tagAndAliasesNames = tagNames
|
||||||
.join(", ")
|
.join(", ")
|
||||||
.concat(args.noaliases ? "" : tagAliasesNames.length > 0 ? `, ${tagAliasesNames.join(", ")}` : "");
|
.concat(args.noaliases ? "" : tagAliasesNames.length > 0 ? `, ${tagAliasesNames.join(", ")}` : "");
|
||||||
|
|
||||||
createChunkedMessage(msg.channel, `Available tags (use with ${prefix}tag): \`\`\`${tagAndAliasesNames}\`\`\``);
|
createChunkedMessage(
|
||||||
|
msg.channel,
|
||||||
|
`Available tags (use with ${prefix}tag/alias): \`\`\`${tagAndAliasesNames}\`\`\``,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -123,6 +123,7 @@ export async function matchAndRenderTagFromString(
|
||||||
const content: StrictMessageContent = {
|
const content: StrictMessageContent = {
|
||||||
content: `Did you mean:\n${lowest[1].join("\n")}`,
|
content: `Did you mean:\n${lowest[1].join("\n")}`,
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
renderedContent: content,
|
renderedContent: content,
|
||||||
tagName: "",
|
tagName: "",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue