3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

More rework progress, mostly done up to ModActions

This commit is contained in:
Dark 2021-06-01 04:33:02 +02:00
parent 52839cc9f3
commit 57893e7f76
No known key found for this signature in database
GPG key ID: 2CD6ACB6B0A87B8A
38 changed files with 199 additions and 241 deletions

View file

@ -2,10 +2,11 @@ import { typedGuildCommand } from "knub";
import { CountersPluginType } from "../types";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { resolveChannel, waitForReply } from "knub/dist/helpers";
import { waitForReply } from "knub/dist/helpers";
import { resolveUser, UnknownUser } from "../../../utils";
import { changeCounterValue } from "../functions/changeCounterValue";
import { TextChannel } from "discord.js";
export const AddCounterCmd = typedGuildCommand<CountersPluginType>()({
trigger: ["counters add", "counter add", "addcounter"],
@ -66,14 +67,14 @@ export const AddCounterCmd = typedGuildCommand<CountersPluginType>()({
let channel = args.channel;
if (!channel && counter.per_channel) {
message.channel.createMessage(`Which channel's counter value would you like to add to?`);
message.channel.send(`Which channel's counter value would you like to add to?`);
const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling");
return;
}
const potentialChannel = resolveChannel(pluginData.guild, reply.content);
const potentialChannel = pluginData.guild.channels.resolve(reply.content);
if (!potentialChannel || !(potentialChannel instanceof TextChannel)) {
sendErrorMessage(pluginData, message.channel, "Channel is not a text channel, cancelling");
return;
@ -84,7 +85,7 @@ export const AddCounterCmd = typedGuildCommand<CountersPluginType>()({
let user = args.user;
if (!user && counter.per_user) {
message.channel.createMessage(`Which user's counter value would you like to add to?`);
message.channel.send(`Which user's counter value would you like to add to?`);
const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling");
@ -102,7 +103,7 @@ export const AddCounterCmd = typedGuildCommand<CountersPluginType>()({
let amount = args.amount;
if (!amount) {
message.channel.createMessage("How much would you like to add to the counter's value?");
message.channel.send("How much would you like to add to the counter's value?");
const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling");
@ -123,19 +124,19 @@ export const AddCounterCmd = typedGuildCommand<CountersPluginType>()({
const counterName = counter.name || args.counterName;
if (channel && user) {
message.channel.createMessage(
message.channel.send(
`Added ${amount} to **${counterName}** for <@!${user.id}> in <#${channel.id}>. The value is now ${newValue}.`,
);
} else if (channel) {
message.channel.createMessage(
message.channel.send(
`Added ${amount} to **${counterName}** in <#${channel.id}>. The value is now ${newValue}.`,
);
} else if (user) {
message.channel.createMessage(
message.channel.send(
`Added ${amount} to **${counterName}** for <@!${user.id}>. The value is now ${newValue}.`,
);
} else {
message.channel.createMessage(`Added ${amount} to **${counterName}**. The value is now ${newValue}.`);
message.channel.send(`Added ${amount} to **${counterName}**. The value is now ${newValue}.`);
}
},
});

View file

@ -41,7 +41,7 @@ export const CountersListCmd = typedGuildCommand<CountersPluginType>()({
hintLines.push(`Use \`${getGuildPrefix(pluginData)}counters reset_all <name>\` to reset a counter entirely`);
}
message.channel.createMessage(
message.channel.send(
trimMultilineString(`
${counterLines.join("\n\n")}

View file

@ -2,11 +2,8 @@ import { typedGuildCommand } from "knub";
import { CountersPluginType } from "../types";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { resolveChannel, waitForReply } from "knub/dist/helpers";
import { confirm, MINUTES, noop, resolveUser, trimMultilineString, UnknownUser } from "../../../utils";
import { changeCounterValue } from "../functions/changeCounterValue";
import { setCounterValue } from "../functions/setCounterValue";
import { confirm, MINUTES, noop, trimMultilineString } from "../../../utils";
import { resetAllCounterValues } from "../functions/resetAllCounterValues";
import { counterIdLock } from "../../../utils/lockNameHelpers";
@ -49,7 +46,7 @@ export const ResetAllCounterValuesCmd = typedGuildCommand<CountersPluginType>()(
}
const loadingMessage = await message.channel
.createMessage(`Resetting counter **${counterName}**. This might take a while. Please don't reload the config.`)
.send(`Resetting counter **${counterName}**. This might take a while. Please don't reload the config.`)
.catch(() => null);
const lock = await pluginData.locks.acquire(counterIdLock(counterId), 10 * MINUTES);

View file

@ -2,10 +2,11 @@ import { typedGuildCommand } from "knub";
import { CountersPluginType } from "../types";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { resolveChannel, waitForReply } from "knub/dist/helpers";
import { waitForReply } from "knub/dist/helpers";
import { resolveUser, UnknownUser } from "../../../utils";
import { setCounterValue } from "../functions/setCounterValue";
import { TextChannel } from "discord.js";
export const ResetCounterCmd = typedGuildCommand<CountersPluginType>()({
trigger: ["counters reset", "counter reset", "resetcounter"],
@ -61,14 +62,14 @@ export const ResetCounterCmd = typedGuildCommand<CountersPluginType>()({
let channel = args.channel;
if (!channel && counter.per_channel) {
message.channel.createMessage(`Which channel's counter value would you like to reset?`);
message.channel.send(`Which channel's counter value would you like to reset?`);
const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling");
return;
}
const potentialChannel = resolveChannel(pluginData.guild, reply.content);
const potentialChannel = pluginData.guild.channels.resolve(reply.content);
if (!potentialChannel || !(potentialChannel instanceof TextChannel)) {
sendErrorMessage(pluginData, message.channel, "Channel is not a text channel, cancelling");
return;
@ -79,7 +80,7 @@ export const ResetCounterCmd = typedGuildCommand<CountersPluginType>()({
let user = args.user;
if (!user && counter.per_user) {
message.channel.createMessage(`Which user's counter value would you like to reset?`);
message.channel.send(`Which user's counter value would you like to reset?`);
const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling");
@ -99,13 +100,13 @@ export const ResetCounterCmd = typedGuildCommand<CountersPluginType>()({
const counterName = counter.name || args.counterName;
if (channel && user) {
message.channel.createMessage(`Reset **${counterName}** for <@!${user.id}> in <#${channel.id}>`);
message.channel.send(`Reset **${counterName}** for <@!${user.id}> in <#${channel.id}>`);
} else if (channel) {
message.channel.createMessage(`Reset **${counterName}** in <#${channel.id}>`);
message.channel.send(`Reset **${counterName}** in <#${channel.id}>`);
} else if (user) {
message.channel.createMessage(`Reset **${counterName}** for <@!${user.id}>`);
message.channel.send(`Reset **${counterName}** for <@!${user.id}>`);
} else {
message.channel.createMessage(`Reset **${counterName}**`);
message.channel.send(`Reset **${counterName}**`);
}
},
});

View file

@ -2,11 +2,11 @@ import { typedGuildCommand } from "knub";
import { CountersPluginType } from "../types";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { resolveChannel, waitForReply } from "knub/dist/helpers";
import { waitForReply } from "knub/dist/helpers";
import { resolveUser, UnknownUser } from "../../../utils";
import { changeCounterValue } from "../functions/changeCounterValue";
import { setCounterValue } from "../functions/setCounterValue";
import { TextChannel } from "discord.js";
export const SetCounterCmd = typedGuildCommand<CountersPluginType>()({
trigger: ["counters set", "counter set", "setcounter"],
@ -67,14 +67,14 @@ export const SetCounterCmd = typedGuildCommand<CountersPluginType>()({
let channel = args.channel;
if (!channel && counter.per_channel) {
message.channel.createMessage(`Which channel's counter value would you like to change?`);
message.channel.send(`Which channel's counter value would you like to change?`);
const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling");
return;
}
const potentialChannel = resolveChannel(pluginData.guild, reply.content);
const potentialChannel = pluginData.guild.channels.resolve(reply.content);
if (!potentialChannel || !(potentialChannel instanceof TextChannel)) {
sendErrorMessage(pluginData, message.channel, "Channel is not a text channel, cancelling");
return;
@ -85,7 +85,7 @@ export const SetCounterCmd = typedGuildCommand<CountersPluginType>()({
let user = args.user;
if (!user && counter.per_user) {
message.channel.createMessage(`Which user's counter value would you like to change?`);
message.channel.send(`Which user's counter value would you like to change?`);
const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling");
@ -103,7 +103,7 @@ export const SetCounterCmd = typedGuildCommand<CountersPluginType>()({
let value = args.value;
if (!value) {
message.channel.createMessage("What would you like to set the counter's value to?");
message.channel.send("What would you like to set the counter's value to?");
const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling");
@ -128,13 +128,13 @@ export const SetCounterCmd = typedGuildCommand<CountersPluginType>()({
const counterName = counter.name || args.counterName;
if (channel && user) {
message.channel.createMessage(`Set **${counterName}** for <@!${user.id}> in <#${channel.id}> to ${value}`);
message.channel.send(`Set **${counterName}** for <@!${user.id}> in <#${channel.id}> to ${value}`);
} else if (channel) {
message.channel.createMessage(`Set **${counterName}** in <#${channel.id}> to ${value}`);
message.channel.send(`Set **${counterName}** in <#${channel.id}> to ${value}`);
} else if (user) {
message.channel.createMessage(`Set **${counterName}** for <@!${user.id}> to ${value}`);
message.channel.send(`Set **${counterName}** for <@!${user.id}> to ${value}`);
} else {
message.channel.createMessage(`Set **${counterName}** to ${value}`);
message.channel.send(`Set **${counterName}** to ${value}`);
}
},
});

View file

@ -2,9 +2,10 @@ import { typedGuildCommand } from "knub";
import { CountersPluginType } from "../types";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { resolveChannel, waitForReply } from "knub/dist/helpers";
import { waitForReply } from "knub/dist/helpers";
import { resolveUser, UnknownUser } from "../../../utils";
import { TextChannel } from "discord.js";
export const ViewCounterCmd = typedGuildCommand<CountersPluginType>()({
trigger: ["counters view", "counter view", "viewcounter", "counter"],
@ -60,14 +61,14 @@ export const ViewCounterCmd = typedGuildCommand<CountersPluginType>()({
let channel = args.channel;
if (!channel && counter.per_channel) {
message.channel.createMessage(`Which channel's counter value would you like to view?`);
message.channel.send(`Which channel's counter value would you like to view?`);
const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling");
return;
}
const potentialChannel = resolveChannel(pluginData.guild, reply.content);
const potentialChannel = pluginData.guild.channels.resolve(reply.content);
if (!potentialChannel || !(potentialChannel instanceof TextChannel)) {
sendErrorMessage(pluginData, message.channel, "Channel is not a text channel, cancelling");
return;
@ -78,7 +79,7 @@ export const ViewCounterCmd = typedGuildCommand<CountersPluginType>()({
let user = args.user;
if (!user && counter.per_user) {
message.channel.createMessage(`Which user's counter value would you like to view?`);
message.channel.send(`Which user's counter value would you like to view?`);
const reply = await waitForReply(pluginData.client, message.channel, message.author.id);
if (!reply || !reply.content) {
sendErrorMessage(pluginData, message.channel, "Cancelling");
@ -99,13 +100,13 @@ export const ViewCounterCmd = typedGuildCommand<CountersPluginType>()({
const counterName = counter.name || args.counterName;
if (channel && user) {
message.channel.createMessage(`**${counterName}** for <@!${user.id}> in <#${channel.id}> is ${finalValue}`);
message.channel.send(`**${counterName}** for <@!${user.id}> in <#${channel.id}> is ${finalValue}`);
} else if (channel) {
message.channel.createMessage(`**${counterName}** in <#${channel.id}> is ${finalValue}`);
message.channel.send(`**${counterName}** in <#${channel.id}> is ${finalValue}`);
} else if (user) {
message.channel.createMessage(`**${counterName}** for <@!${user.id}> is ${finalValue}`);
message.channel.send(`**${counterName}** for <@!${user.id}> is ${finalValue}`);
} else {
message.channel.createMessage(`**${counterName}** is ${finalValue}`);
message.channel.send(`**${counterName}** is ${finalValue}`);
}
},
});