mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-11 04:45:02 +00:00
Add commands to list and reset counters
This commit is contained in:
parent
25a3350196
commit
a568e86d78
8 changed files with 258 additions and 2 deletions
52
backend/src/plugins/Counters/commands/CountersListCmd.ts
Normal file
52
backend/src/plugins/Counters/commands/CountersListCmd.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
import { guildCommand } from "knub";
|
||||
import { CountersPluginType } from "../types";
|
||||
import { sendErrorMessage } from "../../../pluginUtils";
|
||||
import { trimMultilineString, ucfirst } from "../../../utils";
|
||||
import { getGuildPrefix } from "../../../utils/getGuildPrefix";
|
||||
|
||||
export const CountersListCmd = guildCommand<CountersPluginType>()({
|
||||
trigger: ["counters", "counters list", "counter list"],
|
||||
permission: "can_view",
|
||||
|
||||
signature: {},
|
||||
|
||||
async run({ pluginData, message, args }) {
|
||||
const config = pluginData.config.getForMessage(message);
|
||||
|
||||
const countersToShow = Array.from(Object.values(config.counters)).filter(c => c.can_view !== false);
|
||||
if (!countersToShow.length) {
|
||||
sendErrorMessage(pluginData, message.channel, "No counters are configured for this server");
|
||||
return;
|
||||
}
|
||||
|
||||
const counterLines = countersToShow.map(counter => {
|
||||
const title = counter.pretty_name ? `**${counter.pretty_name}** (\`${counter.name}\`)` : `\`${counter.name}\``;
|
||||
|
||||
const types: string[] = [];
|
||||
if (counter.per_user) types.push("per user");
|
||||
if (counter.per_channel) types.push("per channel");
|
||||
const typeInfo = types.length ? types.join(", ") : "global";
|
||||
|
||||
const decayInfo = counter.decay ? `decays ${counter.decay.amount} every ${counter.decay.every}` : null;
|
||||
|
||||
const info = [typeInfo, decayInfo].filter(Boolean);
|
||||
return `${title}\n${ucfirst(info.join("; "))}`;
|
||||
});
|
||||
|
||||
const hintLines = [`Use \`${getGuildPrefix(pluginData)}counters view <name>\` to view a counter's value`];
|
||||
if (config.can_edit) {
|
||||
hintLines.push(`Use \`${getGuildPrefix(pluginData)}counters set <name> <value>\` to change a counter's value`);
|
||||
}
|
||||
if (config.can_reset_all) {
|
||||
hintLines.push(`Use \`${getGuildPrefix(pluginData)}counters reset_all <name>\` to reset a counter entirely`);
|
||||
}
|
||||
|
||||
message.channel.createMessage(
|
||||
trimMultilineString(`
|
||||
${counterLines.join("\n\n")}
|
||||
|
||||
${hintLines.join("\n")}
|
||||
`),
|
||||
);
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue