3
0
Fork 0
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:
Dragory 2021-05-03 19:33:30 +03:00
parent 25a3350196
commit a568e86d78
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
8 changed files with 258 additions and 2 deletions

View 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")}
`),
);
},
});