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

Finish preliminary rework, ready to test

This commit is contained in:
Dark 2021-06-02 04:07:50 +02:00
parent 57893e7f76
commit d0a1beb809
No known key found for this signature in database
GPG key ID: 2CD6ACB6B0A87B8A
177 changed files with 854 additions and 707 deletions

View file

@ -59,7 +59,7 @@ export const AddCaseCmd = modActionsCmd({
return;
}
const reason = formatReasonWithAttachments(args.reason, msg.attachments);
const reason = formatReasonWithAttachments(args.reason, msg.attachments.array());
// Create the case
const casesPlugin = pluginData.getPlugin(CasesPlugin);

View file

@ -6,7 +6,7 @@ import { isBanned } from "../functions/isBanned";
import { readContactMethodsFromArgs } from "../functions/readContactMethodsFromArgs";
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
import { banUserId } from "../functions/banUserId";
import { getMemberLevel, waitForReaction } from "knub/dist/helpers";
import { getMemberLevel } from "knub/dist/helpers";
import humanizeDuration from "humanize-duration";
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
import { CaseTypes } from "../../../data/CaseTypes";
@ -49,7 +49,7 @@ export const BanCmd = modActionsCmd({
}
const time = args["time"] ? args["time"] : null;
const reason = formatReasonWithAttachments(args.reason, msg.attachments);
const reason = formatReasonWithAttachments(args.reason, msg.attachments.array());
const memberToBan = await resolveMember(pluginData.client, pluginData.guild, user.id);
// The moderator who did the action is the message author or, if used, the specified -mod
let mod = msg.member;
@ -76,11 +76,11 @@ export const BanCmd = modActionsCmd({
}
// Ask the mod if we should update the existing ban
const alreadyBannedMsg = await msg.channel.createMessage("User is already banned, update ban?");
const reply = await waitForReaction(pluginData.client, alreadyBannedMsg, ["✅", "❌"], msg.author.id);
const alreadyBannedMsg = await msg.channel.send("User is already banned, update ban?");
const reply = false; // await waitForReaction(pluginData.client, alreadyBannedMsg, ["✅", "❌"], msg.author.id); FIXME waiting on waitForButton
alreadyBannedMsg.delete().catch(noop);
if (!reply || reply.name === "❌") {
if (!reply /* || reply.name === "❌"*/) {
sendErrorMessage(pluginData, msg.channel, "User already banned, update cancelled by moderator");
lock.unlock();
return;
@ -124,11 +124,11 @@ export const BanCmd = modActionsCmd({
}
} else {
// Ask the mod if we should upgrade to a forceban as the user is not on the server
const notOnServerMsg = await msg.channel.createMessage("User not found on the server, forceban instead?");
const reply = await waitForReaction(pluginData.client, notOnServerMsg, ["✅", "❌"], msg.author.id);
const notOnServerMsg = await msg.channel.send("User not found on the server, forceban instead?");
const reply = false; // await waitForReaction(pluginData.client, notOnServerMsg, ["✅", "❌"], msg.author.id); Waiting for waitForButton
notOnServerMsg.delete().catch(noop);
if (!reply || reply.name === "❌") {
if (!reply /*|| reply.name === "❌"*/) {
sendErrorMessage(pluginData, msg.channel, "User not on server, ban cancelled by moderator");
lock.unlock();
return;

View file

@ -24,6 +24,6 @@ export const CaseCmd = modActionsCmd({
const casesPlugin = pluginData.getPlugin(CasesPlugin);
const embed = await casesPlugin.getCaseEmbed(theCase.id, msg.author.id);
msg.channel.createMessage(embed);
msg.channel.send(embed);
},
});

View file

@ -9,6 +9,7 @@ import { getChunkedEmbedFields } from "../../../utils/getChunkedEmbedFields";
import { getDefaultPrefix } from "knub/dist/commands/commandUtils";
import { getGuildPrefix } from "../../../utils/getGuildPrefix";
import { createPaginatedMessage } from "../../../utils/createPaginatedMessage";
import { MessageEmbedOptions, User } from "discord.js";
const opts = {
mod: ct.userId({ option: true }),
@ -55,10 +56,10 @@ export const CasesModCmd = modActionsCmd({
const lastCaseNum = page * casesPerPage;
const title = `Most recent cases ${firstCaseNum}-${lastCaseNum} of ${totalCases} by ${modName}`;
const embed: EmbedOptions = {
const embed: MessageEmbedOptions = {
author: {
name: title,
icon_url: mod instanceof User ? mod.avatarURL || mod.defaultAvatarURL : undefined,
iconURL: mod instanceof User ? mod.avatarURL() || mod.defaultAvatarURL : undefined,
},
fields: [
...getChunkedEmbedFields(emptyEmbedValue, lines.join("\n")),

View file

@ -16,6 +16,7 @@ import { getGuildPrefix } from "../../../utils/getGuildPrefix";
import { getChunkedEmbedFields } from "../../../utils/getChunkedEmbedFields";
import { asyncMap } from "../../../utils/async";
import { CaseTypes } from "../../../data/CaseTypes";
import { MessageEmbedOptions, User } from "discord.js";
const opts = {
expand: ct.bool({ option: true, isSwitch: true, shortcut: "e" }),
@ -75,13 +76,13 @@ export const CasesUserCmd = modActionsCmd({
: `${user.username}#${user.discriminator}`;
if (cases.length === 0) {
msg.channel.createMessage(`No cases found for **${userName}**`);
msg.channel.send(`No cases found for **${userName}**`);
} else {
const casesToDisplay = args.hidden ? cases : normalCases;
if (args.expand) {
if (casesToDisplay.length > 8) {
msg.channel.createMessage("Too many cases for expanded view. Please use compact view instead.");
msg.channel.send("Too many cases for expanded view. Please use compact view instead.");
return;
}
@ -89,7 +90,7 @@ export const CasesUserCmd = modActionsCmd({
const casesPlugin = pluginData.getPlugin(CasesPlugin);
for (const theCase of casesToDisplay) {
const embed = await casesPlugin.getCaseEmbed(theCase.id);
msg.channel.createMessage(embed);
msg.channel.send(embed);
}
} else {
// Compact view (= regular message with a preview of each case)
@ -121,13 +122,13 @@ export const CasesUserCmd = modActionsCmd({
const chunkStart = i * linesPerChunk + 1;
const chunkEnd = Math.min((i + 1) * linesPerChunk, lines.length);
const embed: EmbedOptions = {
const embed: MessageEmbedOptions = {
author: {
name:
lineChunks.length === 1
? `Cases for ${userName} (${lines.length} total)`
: `Cases ${chunkStart}${chunkEnd} of ${lines.length} for ${userName}`,
icon_url: user instanceof User ? user.avatarURL || user.defaultAvatarURL : undefined,
icon_url: user instanceof User ? user.avatarURL() || user.defaultAvatarURL : undefined,
},
fields: [
...getChunkedEmbedFields(emptyEmbedValue, linesInChunk.join("\n")),
@ -135,7 +136,7 @@ export const CasesUserCmd = modActionsCmd({
],
};
msg.channel.createMessage({ embed });
msg.channel.send({ embed });
}
}
}

View file

@ -10,6 +10,7 @@ import { LogType } from "../../../data/LogType";
import moment from "moment-timezone";
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
import { Case } from "../../../data/entities/Case";
import { TextChannel } from "discord.js";
export const DeleteCaseCmd = modActionsCmd({
trigger: ["delete_case", "deletecase"],
@ -49,7 +50,7 @@ export const DeleteCaseCmd = modActionsCmd({
if (!args.force) {
const cases = pluginData.getPlugin(CasesPlugin);
const embedContent = await cases.getCaseEmbed(theCase);
message.channel.createMessage({
message.channel.send({
content: "Delete the following case? Answer 'Yes' to continue, 'No' to cancel.",
embed: embedContent.embed,
});
@ -62,7 +63,7 @@ export const DeleteCaseCmd = modActionsCmd({
);
const normalizedReply = (reply?.content || "").toLowerCase().trim();
if (normalizedReply !== "yes" && normalizedReply !== "y") {
message.channel.createMessage("Cancelled. Case was not deleted.");
message.channel.send("Cancelled. Case was not deleted.");
cancelled++;
continue;
}

View file

@ -61,14 +61,17 @@ export const ForcebanCmd = modActionsCmd({
mod = args.mod;
}
const reason = formatReasonWithAttachments(args.reason, msg.attachments);
const reason = formatReasonWithAttachments(args.reason, msg.attachments.array());
ignoreEvent(pluginData, IgnoredEventType.Ban, user.id);
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_BAN, user.id);
try {
// FIXME: Use banUserId()?
await pluginData.guild.banMember(user.id, 1, reason != null ? encodeURIComponent(reason) : undefined);
await pluginData.guild.bans.create(user.id, {
days: 1,
reason: reason != null ? encodeURIComponent(reason) : undefined,
});
} catch {
sendErrorMessage(pluginData, msg.channel, "Failed to forceban member");
return;

View file

@ -15,6 +15,7 @@ import { LogType } from "../../../data/LogType";
import { performance } from "perf_hooks";
import { humanizeDurationShort } from "../../../humanizeDurationShort";
import { load } from "js-yaml";
import { TextChannel } from "discord.js";
export const MassbanCmd = modActionsCmd({
trigger: "massban",
@ -35,14 +36,14 @@ export const MassbanCmd = modActionsCmd({
}
// Ask for ban reason (cleaner this way instead of trying to cram it into the args)
msg.channel.createMessage("Ban reason? `cancel` to cancel");
msg.channel.send("Ban reason? `cancel` to cancel");
const banReasonReply = await waitForReply(pluginData.client, msg.channel as TextChannel, msg.author.id);
if (!banReasonReply || !banReasonReply.content || banReasonReply.content.toLowerCase().trim() === "cancel") {
sendErrorMessage(pluginData, msg.channel, "Cancelled");
return;
}
const banReason = formatReasonWithAttachments(banReasonReply.content, msg.attachments);
const banReason = formatReasonWithAttachments(banReasonReply.content, msg.attachments.array());
// Verify we can act on each of the users specified
for (const userId of args.userIds) {
@ -60,7 +61,7 @@ export const MassbanCmd = modActionsCmd({
pluginData.state.massbanQueue.length === 0
? "Banning..."
: `Massban queued. Waiting for previous massban to finish (max wait ${maxWaitTimeFormatted}).`;
const loadingMsg = await msg.channel.createMessage(initialLoadingText);
const loadingMsg = await msg.channel.send(initialLoadingText);
const waitTimeStart = performance.now();
const waitingInterval = setInterval(() => {
@ -95,7 +96,10 @@ export const MassbanCmd = modActionsCmd({
ignoreEvent(pluginData, IgnoredEventType.Ban, userId, 120 * 1000);
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_BAN, userId, 120 * 1000);
await pluginData.guild.banMember(userId, 1, banReason != null ? encodeURIComponent(banReason) : undefined);
await pluginData.guild.bans.create(userId, {
days: 1,
reason: banReason != null ? encodeURIComponent(banReason) : undefined,
});
await casesPlugin.createCase({
userId,

View file

@ -10,6 +10,7 @@ import { waitForReply } from "knub/dist/helpers";
import { ignoreEvent } from "../functions/ignoreEvent";
import { CasesPlugin } from "../../Cases/CasesPlugin";
import { LogType } from "../../../data/LogType";
import { TextChannel } from "discord.js";
export const MassunbanCmd = modActionsCmd({
trigger: "massunban",
@ -30,14 +31,14 @@ export const MassunbanCmd = modActionsCmd({
}
// Ask for unban reason (cleaner this way instead of trying to cram it into the args)
msg.channel.createMessage("Unban reason? `cancel` to cancel");
msg.channel.send("Unban reason? `cancel` to cancel");
const unbanReasonReply = await waitForReply(pluginData.client, msg.channel as TextChannel, msg.author.id);
if (!unbanReasonReply || !unbanReasonReply.content || unbanReasonReply.content.toLowerCase().trim() === "cancel") {
sendErrorMessage(pluginData, msg.channel, "Cancelled");
return;
}
const unbanReason = formatReasonWithAttachments(unbanReasonReply.content, msg.attachments);
const unbanReason = formatReasonWithAttachments(unbanReasonReply.content, msg.attachments.array());
// Ignore automatic unban cases and logs for these users
// We'll create our own cases below and post a single "mass unbanned" log instead
@ -48,7 +49,7 @@ export const MassunbanCmd = modActionsCmd({
});
// Show a loading indicator since this can take a while
const loadingMsg = await msg.channel.createMessage("Unbanning...");
const loadingMsg = await msg.channel.send("Unbanning...");
// Unban each user and count failed unbans (if any)
const failedUnbans: Array<{ userId: string; reason: UnbanFailReasons }> = [];
@ -60,7 +61,7 @@ export const MassunbanCmd = modActionsCmd({
}
try {
await pluginData.guild.unbanMember(userId, unbanReason != null ? encodeURIComponent(unbanReason) : undefined);
await pluginData.guild.bans.remove(userId, unbanReason != null ? encodeURIComponent(unbanReason) : undefined);
await casesPlugin.createCase({
userId,

View file

@ -8,6 +8,7 @@ import { waitForReply } from "knub/dist/helpers";
import { LogType } from "../../../data/LogType";
import { logger } from "../../../logger";
import { MutesPlugin } from "../../../plugins/Mutes/MutesPlugin";
import { TextChannel } from "discord.js";
export const MassmuteCmd = modActionsCmd({
trigger: "massmute",
@ -28,7 +29,7 @@ export const MassmuteCmd = modActionsCmd({
}
// Ask for mute reason
msg.channel.createMessage("Mute reason? `cancel` to cancel");
msg.channel.send("Mute reason? `cancel` to cancel");
const muteReasonReceived = await waitForReply(pluginData.client, msg.channel as TextChannel, msg.author.id);
if (
!muteReasonReceived ||
@ -39,7 +40,7 @@ export const MassmuteCmd = modActionsCmd({
return;
}
const muteReason = formatReasonWithAttachments(muteReasonReceived.content, msg.attachments);
const muteReason = formatReasonWithAttachments(muteReasonReceived.content, msg.attachments.array());
// Verify we can act upon all users
for (const userId of args.userIds) {
@ -58,7 +59,7 @@ export const MassmuteCmd = modActionsCmd({
});
// Show loading indicator
const loadingMsg = await msg.channel.createMessage("Muting...");
const loadingMsg = await msg.channel.send("Muting...");
// Mute everyone and count fails
const modId = msg.author.id;

View file

@ -1,16 +1,8 @@
import { modActionsCmd } from "../types";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { Case } from "../../../data/entities/Case";
import { canActOn, hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
import { CasesPlugin } from "../../Cases/CasesPlugin";
import { LogType } from "../../../data/LogType";
import { CaseTypes } from "../../../data/CaseTypes";
import { errorMessage, noop, resolveMember, resolveUser, stripObjectToScalars } from "../../../utils";
import { canActOn, sendErrorMessage } from "../../../pluginUtils";
import { noop, resolveMember, resolveUser } from "../../../utils";
import { isBanned } from "../functions/isBanned";
import { waitForReaction } from "knub/dist/helpers";
import { readContactMethodsFromArgs } from "../functions/readContactMethodsFromArgs";
import { warnMember } from "../functions/warnMember";
import { actualMuteUserCmd } from "../functions/actualMuteUserCmd";
@ -62,11 +54,11 @@ export const MuteCmd = modActionsCmd({
return;
} else {
// Ask the mod if we should upgrade to a forcemute as the user is not on the server
const notOnServerMsg = await msg.channel.createMessage("User not found on the server, forcemute instead?");
const reply = await waitForReaction(pluginData.client, notOnServerMsg, ["✅", "❌"], msg.author.id);
const notOnServerMsg = await msg.channel.send("User not found on the server, forcemute instead?");
const reply = false; // await waitForReaction(pluginData.client, notOnServerMsg, ["✅", "❌"], msg.author.id); FIXME waiting on waitForButton
notOnServerMsg.delete().catch(noop);
if (!reply || reply.name === "❌") {
if (!reply /*|| reply.name === "❌"*/) {
sendErrorMessage(pluginData, msg.channel, "User not on server, mute cancelled by moderator");
return;
}

View file

@ -25,13 +25,13 @@ export const NoteCmd = modActionsCmd({
return;
}
if (!args.note && msg.attachments.length === 0) {
if (!args.note && msg.attachments.size === 0) {
sendErrorMessage(pluginData, msg.channel, "Text or attachment required");
return;
}
const userName = `${user.username}#${user.discriminator}`;
const reason = formatReasonWithAttachments(args.note, msg.attachments);
const reason = formatReasonWithAttachments(args.note, msg.attachments.array());
const casesPlugin = pluginData.getPlugin(CasesPlugin);
const createdCase = await casesPlugin.createCase({

View file

@ -28,7 +28,7 @@ export const SoftbanCmd = modActionsCmd({
async run({ pluginData, message: msg, args }) {
await actualKickMemberCmd(pluginData, msg, { clean: true, ...args });
await msg.channel.createMessage(
await msg.channel.send(
"Softban will be removed in the future - please use the kick command with the `-clean` argument instead!",
);
},

View file

@ -45,11 +45,11 @@ export const UnbanCmd = modActionsCmd({
}
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_UNBAN, user.id);
const reason = formatReasonWithAttachments(args.reason, msg.attachments);
const reason = formatReasonWithAttachments(args.reason, msg.attachments.array());
try {
ignoreEvent(pluginData, IgnoredEventType.Unban, user.id);
await pluginData.guild.unbanMember(user.id, reason != null ? encodeURIComponent(reason) : undefined);
await pluginData.guild.bans.remove(user.id, reason != null ? encodeURIComponent(reason) : undefined);
} catch {
sendErrorMessage(pluginData, msg.channel, "Failed to unban member; are you sure they're banned?");
return;

View file

@ -5,7 +5,6 @@ import { resolveUser, resolveMember, noop } from "../../../utils";
import { MutesPlugin } from "../../../plugins/Mutes/MutesPlugin";
import { actualUnmuteCmd } from "../functions/actualUnmuteUserCmd";
import { isBanned } from "../functions/isBanned";
import { waitForReaction } from "knub/dist/helpers";
const opts = {
mod: ct.member({ option: true }),
@ -61,11 +60,11 @@ export const UnmuteCmd = modActionsCmd({
return;
} else {
// Ask the mod if we should upgrade to a forceunmute as the user is not on the server
const notOnServerMsg = await msg.channel.createMessage("User not found on the server, forceunmute instead?");
const reply = await waitForReaction(pluginData.client, notOnServerMsg, ["✅", "❌"], msg.author.id);
const notOnServerMsg = await msg.channel.send("User not found on the server, forceunmute instead?");
const reply = false; //await waitForReaction(pluginData.client, notOnServerMsg, ["✅", "❌"], msg.author.id); FIXME waiting on waitForButton
notOnServerMsg.delete().catch(noop);
if (!reply || reply.name === "❌") {
if (!reply /*|| reply.name === "❌"*/) {
sendErrorMessage(pluginData, msg.channel, "User not on server, unmute cancelled by moderator");
return;
}

View file

@ -8,9 +8,9 @@ import { LogType } from "../../../data/LogType";
import { CaseTypes } from "../../../data/CaseTypes";
import { errorMessage, resolveMember, resolveUser, stripObjectToScalars } from "../../../utils";
import { isBanned } from "../functions/isBanned";
import { waitForReaction } from "knub/dist/helpers";
import { readContactMethodsFromArgs } from "../functions/readContactMethodsFromArgs";
import { warnMember } from "../functions/warnMember";
import { TextChannel } from "discord.js";
export const WarnCmd = modActionsCmd({
trigger: "warn",
@ -56,7 +56,7 @@ export const WarnCmd = modActionsCmd({
let mod = msg.member;
if (args.mod) {
if (!(await hasPermission(pluginData, "can_act_as_other", { message: msg }))) {
msg.channel.createMessage(errorMessage("You don't have permission to use -mod"));
msg.channel.send(errorMessage("You don't have permission to use -mod"));
return;
}
@ -64,19 +64,19 @@ export const WarnCmd = modActionsCmd({
}
const config = pluginData.config.get();
const reason = formatReasonWithAttachments(args.reason, msg.attachments);
const reason = formatReasonWithAttachments(args.reason, msg.attachments.array());
const casesPlugin = pluginData.getPlugin(CasesPlugin);
const priorWarnAmount = await casesPlugin.getCaseTypeAmountForUserId(memberToWarn.id, CaseTypes.Warn);
if (config.warn_notify_enabled && priorWarnAmount >= config.warn_notify_threshold) {
const tooManyWarningsMsg = await msg.channel.createMessage(
const tooManyWarningsMsg = await msg.channel.send(
config.warn_notify_message.replace("{priorWarnings}", `${priorWarnAmount}`),
);
const reply = await waitForReaction(pluginData.client, tooManyWarningsMsg, ["✅", "❌"], msg.author.id);
const reply = false; //await waitForReaction(pluginData.client, tooManyWarningsMsg, ["✅", "❌"], msg.author.id); FIXME waiting on waitForButton
tooManyWarningsMsg.delete();
if (!reply || reply.name === "❌") {
msg.channel.createMessage(errorMessage("Warn cancelled by moderator"));
if (!reply /*|| reply.name === "❌"*/) {
msg.channel.send(errorMessage("Warn cancelled by moderator"));
return;
}
}