3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-11 20:55:01 +00:00

Update djs & knub (#395)

* update pkgs

Signed-off-by: GitHub <noreply@github.com>

* new knub typings

Signed-off-by: GitHub <noreply@github.com>

* more pkg updates

Signed-off-by: GitHub <noreply@github.com>

* more fixes

Signed-off-by: GitHub <noreply@github.com>

* channel typings

Signed-off-by: GitHub <noreply@github.com>

* more message utils typings fixes

Signed-off-by: GitHub <noreply@github.com>

* migrate permissions

Signed-off-by: GitHub <noreply@github.com>

* fix: InternalPoster webhookables

Signed-off-by: GitHub <noreply@github.com>

* djs typings: Attachment & Util

Signed-off-by: GitHub <noreply@github.com>

* more typings

Signed-off-by: GitHub <noreply@github.com>

* fix: rename permissionNames

Signed-off-by: GitHub <noreply@github.com>

* more fixes

Signed-off-by: GitHub <noreply@github.com>

* half the number of errors

* knub commands => messageCommands

Signed-off-by: GitHub <noreply@github.com>

* configPreprocessor => configParser

Signed-off-by: GitHub <noreply@github.com>

* fix channel.messages

Signed-off-by: GitHub <noreply@github.com>

* revert automod any typing

Signed-off-by: GitHub <noreply@github.com>

* more configParser typings

Signed-off-by: GitHub <noreply@github.com>

* revert

Signed-off-by: GitHub <noreply@github.com>

* remove knub type params

Signed-off-by: GitHub <noreply@github.com>

* fix more MessageEmbed / MessageOptions

Signed-off-by: GitHub <noreply@github.com>

* dumb commit for @almeidx to see why this is stupid

Signed-off-by: GitHub <noreply@github.com>

* temp disable custom_events

Signed-off-by: GitHub <noreply@github.com>

* more minor typings fixes - 23 err left

Signed-off-by: GitHub <noreply@github.com>

* update djs dep

* +debug build method (revert this)

Signed-off-by: GitHub <noreply@github.com>

* Revert "+debug build method (revert this)"

This reverts commit a80af1e729.

* Redo +debug build (Revert this)

Signed-off-by: GitHub <noreply@github.com>

* uniform before/after Load shorthands

Signed-off-by: GitHub <noreply@github.com>

* remove unused imports & add prettier plugin

Signed-off-by: GitHub <noreply@github.com>

* env fixes for web platform hosting

Signed-off-by: GitHub <noreply@github.com>

* feat: knub v32-next; related fixes

* fix: allow legacy keys in change_perms action

* fix: request Message Content intent

* fix: use Knub's config validation logic in API

* fix(dashboard): fix error when there are no message and/or slash commands in a plugin

* fix(automod): start_thread action thread options

* fix(CustomEvents): message command types

* chore: remove unneeded type annotation

* feat: add forum channel icon; use thread icon for news threads

* chore: make tslint happy

* chore: fix formatting

---------

Signed-off-by: GitHub <noreply@github.com>
Co-authored-by: almeidx <almeidx@pm.me>
Co-authored-by: Dragory <2606411+Dragory@users.noreply.github.com>
This commit is contained in:
Tiago R 2023-04-01 12:58:17 +01:00 committed by GitHub
parent 293115af22
commit 06877e90cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
476 changed files with 2965 additions and 3251 deletions

View file

@ -1,9 +1,9 @@
import { GuildMember, TextChannel, ThreadChannel } from "discord.js";
import { GuildMember, GuildTextBasedChannel } from "discord.js";
import { GuildPluginData } from "knub";
import { hasPermission } from "knub/dist/helpers";
import { hasPermission } from "knub/helpers";
import { LogType } from "../../../data/LogType";
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { errorMessage, resolveMember, resolveUser } from "../../../utils";
import { DAYS, errorMessage, resolveMember, resolveUser, SECONDS } from "../../../utils";
import { IgnoredEventType, ModActionsPluginType } from "../types";
import { formatReasonWithAttachments } from "./formatReasonWithAttachments";
import { ignoreEvent } from "./ignoreEvent";
@ -19,7 +19,7 @@ export async function actualKickMemberCmd(
reason: string;
mod: GuildMember;
notify?: string;
"notify-channel"?: TextChannel | ThreadChannel;
"notify-channel"?: GuildTextBasedChannel;
clean?: boolean;
},
) {
@ -82,7 +82,7 @@ export async function actualKickMemberCmd(
ignoreEvent(pluginData, IgnoredEventType.Ban, memberToKick.id);
try {
await memberToKick.ban({ days: 1, reason: "kick -clean" });
await memberToKick.ban({ deleteMessageSeconds: (1 * DAYS) / SECONDS, reason: "kick -clean" });
} catch {
sendErrorMessage(pluginData, msg.channel, "Failed to ban the user to clean messages (-clean)");
}

View file

@ -1,4 +1,4 @@
import { GuildMember, Message, TextChannel, ThreadChannel, User } from "discord.js";
import { GuildMember, GuildTextBasedChannel, Message, User } from "discord.js";
import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub";
import { logger } from "../../../logger";
@ -24,7 +24,7 @@ export async function actualMuteUserCmd(
reason?: string;
mod: GuildMember;
notify?: string;
"notify-channel"?: TextChannel | ThreadChannel;
"notify-channel"?: GuildTextBasedChannel;
},
) {
// The moderator who did the action is the message author or, if used, the specified -mod
@ -33,7 +33,7 @@ export async function actualMuteUserCmd(
if (args.mod) {
if (!(await hasPermission(pluginData, "can_act_as_other", { message: msg }))) {
sendErrorMessage(pluginData, msg.channel as TextChannel, "You don't have permission to use -mod");
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod");
return;
}
@ -51,7 +51,7 @@ export async function actualMuteUserCmd(
try {
contactMethods = readContactMethodsFromArgs(args);
} catch (e) {
sendErrorMessage(pluginData, msg.channel as TextChannel, e.message);
sendErrorMessage(pluginData, msg.channel, e.message);
return;
}
@ -65,9 +65,9 @@ export async function actualMuteUserCmd(
});
} catch (e) {
if (e instanceof RecoverablePluginError && e.code === ERRORS.NO_MUTE_ROLE_IN_CONFIG) {
sendErrorMessage(pluginData, msg.channel as TextChannel, "Could not mute the user: no mute role set in config");
sendErrorMessage(pluginData, msg.channel, "Could not mute the user: no mute role set in config");
} else if (isDiscordAPIError(e) && e.code === 10007) {
sendErrorMessage(pluginData, msg.channel as TextChannel, "Could not mute the user: unknown member");
sendErrorMessage(pluginData, msg.channel, "Could not mute the user: unknown member");
} else {
logger.error(`Failed to mute user ${user.id}: ${e.stack}`);
if (user.id == null) {
@ -75,14 +75,14 @@ export async function actualMuteUserCmd(
// tslint:disable-next-line:no-console
console.trace("[DEBUG] Null user.id for mute");
}
sendErrorMessage(pluginData, msg.channel as TextChannel, "Could not mute the user");
sendErrorMessage(pluginData, msg.channel, "Could not mute the user");
}
return;
}
// Confirm the action to the moderator
let response;
let response: string;
if (args.time) {
if (muteResult.updatedExistingMute) {
response = asSingleLine(`
@ -110,5 +110,5 @@ export async function actualMuteUserCmd(
}
if (muteResult.notifyResult.text) response += ` (${muteResult.notifyResult.text})`;
sendSuccessMessage(pluginData, msg.channel as TextChannel, response);
sendSuccessMessage(pluginData, msg.channel, response);
}

View file

@ -1,4 +1,4 @@
import { GuildMember, Message, TextChannel, User } from "discord.js";
import { GuildMember, Message, User } from "discord.js";
import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub";
import { MutesPlugin } from "../../../plugins/Mutes/MutesPlugin";
@ -19,7 +19,7 @@ export async function actualUnmuteCmd(
if (args.mod) {
if (!(await hasPermission(pluginData, "can_act_as_other", { message: msg, channelId: msg.channel.id }))) {
sendErrorMessage(pluginData, msg.channel as TextChannel, "You don't have permission to use -mod");
sendErrorMessage(pluginData, msg.channel, "You don't have permission to use -mod");
return;
}
@ -37,7 +37,7 @@ export async function actualUnmuteCmd(
});
if (!result) {
sendErrorMessage(pluginData, msg.channel as TextChannel, "User is not muted!");
sendErrorMessage(pluginData, msg.channel, "User is not muted!");
return;
}
@ -46,7 +46,7 @@ export async function actualUnmuteCmd(
const timeUntilUnmute = args.time && humanizeDuration(args.time);
sendSuccessMessage(
pluginData,
msg.channel as TextChannel,
msg.channel,
asSingleLine(`
Unmuting **${user.tag}**
in ${timeUntilUnmute} (Case #${result.case.case_number})
@ -55,7 +55,7 @@ export async function actualUnmuteCmd(
} else {
sendSuccessMessage(
pluginData,
msg.channel as TextChannel,
msg.channel,
asSingleLine(`
Unmuted **${user.tag}**
(Case #${result.case.case_number})

View file

@ -1,25 +1,26 @@
import { DiscordAPIError, Snowflake, User } from "discord.js";
import humanizeDuration from "humanize-duration";
import { GuildPluginData } from "knub";
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { CaseTypes } from "../../../data/CaseTypes";
import { LogType } from "../../../data/LogType";
import { registerExpiringTempban } from "../../../data/loops/expiringTempbansLoop";
import { logger } from "../../../logger";
import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter";
import {
createUserNotificationError,
DAYS,
notifyUser,
resolveUser,
stripObjectToScalars,
SECONDS,
ucfirst,
UserNotificationResult,
} from "../../../utils";
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { CasesPlugin } from "../../Cases/CasesPlugin";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { BanOptions, BanResult, IgnoredEventType, ModActionsPluginType } from "../types";
import { getDefaultContactMethods } from "./getDefaultContactMethods";
import { ignoreEvent } from "./ignoreEvent";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { registerExpiringTempban } from "../../../data/loops/expiringTempbansLoop";
/**
* Ban the specified user id, whether or not they're actually on the server at the time. Generates a case.
@ -87,7 +88,7 @@ export async function banUserId(
try {
const deleteMessageDays = Math.min(7, Math.max(0, banOptions.deleteMessageDays ?? 1));
await pluginData.guild.bans.create(userId as Snowflake, {
days: deleteMessageDays,
deleteMessageSeconds: (deleteMessageDays * DAYS) / SECONDS,
reason: reason ?? undefined,
});
} catch (e) {

View file

@ -5,14 +5,14 @@ import moment from "moment-timezone";
import { LogType } from "src/data/LogType";
import { logger } from "src/logger";
import { CaseTypes } from "../../../data/CaseTypes";
import { resolveUser, SECONDS } from "../../../utils";
import { Tempban } from "../../../data/entities/Tempban";
import { resolveUser } from "../../../utils";
import { CasesPlugin } from "../../Cases/CasesPlugin";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { IgnoredEventType, ModActionsPluginType } from "../types";
import { formatReasonWithAttachments } from "./formatReasonWithAttachments";
import { ignoreEvent } from "./ignoreEvent";
import { isBanned } from "./isBanned";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { Tempban } from "../../../data/entities/Tempban";
export async function clearTempban(pluginData: GuildPluginData<ModActionsPluginType>, tempban: Tempban) {
if (!(await isBanned(pluginData, tempban.user_id))) {

View file

@ -1,6 +1,6 @@
import { MessageAttachment } from "discord.js";
import { Attachment } from "discord.js";
export function formatReasonWithAttachments(reason: string, attachments: MessageAttachment[]) {
export function formatReasonWithAttachments(reason: string, attachments: Attachment[]) {
const attachmentUrls = attachments.map((a) => a.url);
return ((reason || "") + " " + attachmentUrls.join(" ")).trim();
}

View file

@ -1,6 +1,5 @@
import { Permissions, Snowflake } from "discord.js";
import { PermissionsBitField, Snowflake } from "discord.js";
import { GuildPluginData } from "knub";
import { LogType } from "../../../data/LogType";
import { isDiscordAPIError, isDiscordHTTPError, SECONDS, sleep } from "../../../utils";
import { hasDiscordPermissions } from "../../../utils/hasDiscordPermissions";
import { LogsPlugin } from "../../Logs/LogsPlugin";
@ -12,7 +11,7 @@ export async function isBanned(
timeout: number = 5 * SECONDS,
): Promise<boolean> {
const botMember = pluginData.guild.members.cache.get(pluginData.client.user!.id);
if (botMember && !hasDiscordPermissions(botMember.permissions, Permissions.FLAGS.BAN_MEMBERS)) {
if (botMember && !hasDiscordPermissions(botMember.permissions, PermissionsBitField.Flags.BanMembers)) {
pluginData.getPlugin(LogsPlugin).logBotAlert({
body: `Missing "Ban Members" permission to check for existing bans`,
});

View file

@ -1,15 +1,15 @@
import { GuildMember } from "discord.js";
import { GuildPluginData } from "knub";
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { CaseTypes } from "../../../data/CaseTypes";
import { LogType } from "../../../data/LogType";
import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter";
import { createUserNotificationError, notifyUser, resolveUser, ucfirst, UserNotificationResult } from "../../../utils";
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { CasesPlugin } from "../../Cases/CasesPlugin";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { IgnoredEventType, KickOptions, KickResult, ModActionsPluginType } from "../types";
import { getDefaultContactMethods } from "./getDefaultContactMethods";
import { ignoreEvent } from "./ignoreEvent";
import { LogsPlugin } from "../../Logs/LogsPlugin";
/**
* Kick the specified server member. Generates a case.

View file

@ -1,9 +1,9 @@
import { TextChannel, ThreadChannel } from "discord.js";
import { GuildTextBasedChannel } from "discord.js";
import { disableUserNotificationStrings, UserNotificationMethod } from "../../../utils";
export function readContactMethodsFromArgs(args: {
notify?: string;
"notify-channel"?: TextChannel | ThreadChannel;
"notify-channel"?: GuildTextBasedChannel;
}): null | UserNotificationMethod[] {
if (args.notify) {
if (args.notify === "dm") {

View file

@ -1,11 +1,10 @@
import { Message, TextChannel } from "discord.js";
import { Message } from "discord.js";
import { CaseTypes } from "../../../data/CaseTypes";
import { Case } from "../../../data/entities/Case";
import { LogType } from "../../../data/LogType";
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { formatReasonWithAttachments } from "./formatReasonWithAttachments";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { formatReasonWithAttachments } from "./formatReasonWithAttachments";
export async function updateCase(pluginData, msg: Message, args) {
let theCase: Case | undefined;
@ -16,12 +15,12 @@ export async function updateCase(pluginData, msg: Message, args) {
}
if (!theCase) {
sendErrorMessage(pluginData, msg.channel as TextChannel, "Case not found");
sendErrorMessage(pluginData, msg.channel, "Case not found");
return;
}
if (!args.note && msg.attachments.size === 0) {
sendErrorMessage(pluginData, msg.channel as TextChannel, "Text or attachment required");
sendErrorMessage(pluginData, msg.channel, "Text or attachment required");
return;
}
@ -41,5 +40,5 @@ export async function updateCase(pluginData, msg: Message, args) {
note,
});
sendSuccessMessage(pluginData, msg.channel as TextChannel, `Case \`#${theCase.case_number}\` updated`);
sendSuccessMessage(pluginData, msg.channel, `Case \`#${theCase.case_number}\` updated`);
}

View file

@ -1,15 +1,14 @@
import { GuildMember, Snowflake } from "discord.js";
import { GuildPluginData } from "knub";
import { memberToTemplateSafeMember, userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { CaseTypes } from "../../../data/CaseTypes";
import { LogType } from "../../../data/LogType";
import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter";
import { createUserNotificationError, notifyUser, resolveUser, ucfirst, UserNotificationResult } from "../../../utils";
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { waitForButtonConfirm } from "../../../utils/waitForInteraction";
import { CasesPlugin } from "../../Cases/CasesPlugin";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { ModActionsPluginType, WarnOptions, WarnResult } from "../types";
import { getDefaultContactMethods } from "./getDefaultContactMethods";
import { LogsPlugin } from "../../Logs/LogsPlugin";
export async function warnMember(
pluginData: GuildPluginData<ModActionsPluginType>,