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

Turn on strict TS compilation. Fix up and tweak types accordingly.

This commit is contained in:
Dragory 2020-11-09 20:03:57 +02:00
parent 690955a399
commit 629002b8d9
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
172 changed files with 720 additions and 534 deletions

View file

@ -65,7 +65,7 @@ export const AddCaseCmd = modActionsCmd({
modId: mod.id,
type: CaseTypes[type],
reason,
ppId: mod.id !== msg.author.id ? msg.author.id : null,
ppId: mod.id !== msg.author.id ? msg.author.id : undefined,
});
if (user) {

View file

@ -78,7 +78,7 @@ export const BanCmd = modActionsCmd({
contactMethods,
caseArgs: {
modId: mod.id,
ppId: mod.id !== msg.author.id ? msg.author.id : null,
ppId: mod.id !== msg.author.id ? msg.author.id : undefined,
},
deleteMessageDays,
});

View file

@ -9,6 +9,7 @@ import { LogsPlugin } from "../../Logs/LogsPlugin";
import { LogType } from "../../../data/LogType";
import moment from "moment-timezone";
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
import { Case } from "../../../data/entities/Case";
export const DeleteCaseCmd = modActionsCmd({
trigger: ["delete_case", "deletecase"],
@ -25,8 +26,8 @@ export const DeleteCaseCmd = modActionsCmd({
},
async run({ pluginData, message, args }) {
const failed = [];
const validCases = [];
const failed: number[] = [];
const validCases: Case[] = [];
let cancelled = 0;
for (const num of args.caseNumber) {

View file

@ -77,7 +77,7 @@ export const ForcebanCmd = modActionsCmd({
modId: mod.id,
type: CaseTypes.Ban,
reason,
ppId: mod.id !== msg.author.id ? msg.author.id : null,
ppId: mod.id !== msg.author.id ? msg.author.id : undefined,
});
// Confirm the action

View file

@ -14,7 +14,7 @@ export const HideCaseCmd = modActionsCmd({
],
async run({ pluginData, message: msg, args }) {
const failed = [];
const failed: number[] = [];
for (const num of args.caseNum) {
const theCase = await pluginData.state.cases.findByCaseNumber(num);

View file

@ -62,7 +62,7 @@ export const MassbanCmd = modActionsCmd({
const loadingMsg = await msg.channel.createMessage("Banning...");
// Ban each user and count failed bans (if any)
const failedBans = [];
const failedBans: string[] = [];
const casesPlugin = pluginData.getPlugin(CasesPlugin);
for (const userId of args.userIds) {
try {

View file

@ -62,7 +62,7 @@ export const MassmuteCmd = modActionsCmd({
// Mute everyone and count fails
const modId = msg.author.id;
const failedMutes = [];
const failedMutes: string[] = [];
const mutesPlugin = pluginData.getPlugin(MutesPlugin);
for (const userId of args.userIds) {
try {

View file

@ -59,7 +59,7 @@ export const UnbanCmd = modActionsCmd({
modId: mod.id,
type: CaseTypes.Unban,
reason,
ppId: mod.id !== msg.author.id ? msg.author.id : null,
ppId: mod.id !== msg.author.id ? msg.author.id : undefined,
});
// Confirm the action

View file

@ -14,7 +14,7 @@ export const UnhideCaseCmd = modActionsCmd({
],
async run({ pluginData, message: msg, args }) {
const failed = [];
const failed: number[] = [];
for (const num of args.caseNum) {
const theCase = await pluginData.state.cases.findByCaseNumber(num);

View file

@ -24,7 +24,7 @@ export const UpdateCmd = modActionsCmd({
],
async run({ pluginData, message: msg, args }) {
let theCase: Case;
let theCase: Case | undefined;
if (args.caseNumber != null) {
theCase = await pluginData.state.cases.findByCaseNumber(args.caseNumber);
} else {

View file

@ -91,7 +91,7 @@ export const WarnCmd = modActionsCmd({
contactMethods,
caseArgs: {
modId: mod.id,
ppId: mod.id !== msg.author.id ? msg.author.id : null,
ppId: mod.id !== msg.author.id ? msg.author.id : undefined,
reason,
},
retryPromptChannel: msg.channel as TextChannel,

View file

@ -1,12 +1,12 @@
import { IgnoredEventType, modActionsEvt } from "../types";
import { isEventIgnored } from "../functions/isEventIgnored";
import { clearIgnoredEvents } from "../functions/clearIgnoredEvents";
import { Constants as ErisConstants } from "eris";
import { Constants as ErisConstants, User } from "eris";
import { CasesPlugin } from "../../Cases/CasesPlugin";
import { CaseTypes } from "../../../data/CaseTypes";
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";
import { LogType } from "../../../data/LogType";
import { stripObjectToScalars, resolveUser } from "../../../utils";
import { stripObjectToScalars, resolveUser, UnknownUser } from "../../../utils";
/**
* Create a BAN case automatically when a user is banned manually.
@ -29,27 +29,27 @@ export const CreateBanCaseOnManualBanEvt = modActionsEvt(
const casesPlugin = pluginData.getPlugin(CasesPlugin);
let createdCase;
let mod = null;
let mod: User | UnknownUser | null = null;
let reason = "";
if (relevantAuditLogEntry) {
const modId = relevantAuditLogEntry.user.id;
const auditLogId = relevantAuditLogEntry.id;
mod = resolveUser(pluginData.client, modId);
reason = relevantAuditLogEntry.reason;
mod = await resolveUser(pluginData.client, modId);
reason = relevantAuditLogEntry.reason || "";
createdCase = await casesPlugin.createCase({
userId: user.id,
modId,
type: CaseTypes.Ban,
auditLogId,
reason,
reason: reason || undefined,
automatic: true,
});
} else {
createdCase = await casesPlugin.createCase({
userId: user.id,
modId: null,
modId: "0",
type: CaseTypes.Ban,
});
}

View file

@ -41,7 +41,7 @@ export const CreateKickCaseOnManualKickEvt = modActionsEvt(
modId: kickAuditLogEntry.user.id,
type: CaseTypes.Kick,
auditLogId: kickAuditLogEntry.id,
reason: kickAuditLogEntry.reason,
reason: kickAuditLogEntry.reason || undefined,
automatic: true,
});
}

View file

@ -1,11 +1,11 @@
import { IgnoredEventType, modActionsEvt } from "../types";
import { isEventIgnored } from "../functions/isEventIgnored";
import { clearIgnoredEvents } from "../functions/clearIgnoredEvents";
import { Constants as ErisConstants } from "eris";
import { Constants as ErisConstants, User } from "eris";
import { CasesPlugin } from "../../Cases/CasesPlugin";
import { CaseTypes } from "../../../data/CaseTypes";
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";
import { stripObjectToScalars, resolveUser } from "../../../utils";
import { stripObjectToScalars, resolveUser, UnknownUser } from "../../../utils";
import { LogType } from "../../../data/LogType";
/**
@ -29,13 +29,13 @@ export const CreateUnbanCaseOnManualUnbanEvt = modActionsEvt(
const casesPlugin = pluginData.getPlugin(CasesPlugin);
let createdCase;
let mod = null;
let mod: User | UnknownUser | null = null;
if (relevantAuditLogEntry) {
const modId = relevantAuditLogEntry.user.id;
const auditLogId = relevantAuditLogEntry.id;
mod = resolveUser(pluginData.client, modId);
mod = await resolveUser(pluginData.client, modId);
createdCase = await casesPlugin.createCase({
userId: user.id,
modId,
@ -46,7 +46,7 @@ export const CreateUnbanCaseOnManualUnbanEvt = modActionsEvt(
} else {
createdCase = await casesPlugin.createCase({
userId: user.id,
modId: null,
modId: "0",
type: CaseTypes.Unban,
automatic: true,
});

View file

@ -10,6 +10,7 @@ import { MutesPlugin } from "../../Mutes/MutesPlugin";
import { readContactMethodsFromArgs } from "./readContactMethodsFromArgs";
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError";
import { logger } from "../../../logger";
import { GuildMessage } from "knub/dist/helpers";
/**
* The actual function run by both !mute and !forcemute.
@ -18,12 +19,12 @@ import { logger } from "../../../logger";
export async function actualMuteUserCmd(
pluginData: GuildPluginData<ModActionsPluginType>,
user: User | UnknownUser,
msg: Message,
msg: GuildMessage,
args: { time?: number; reason?: string; mod: Member; notify?: string; "notify-channel"?: TextChannel },
) {
// The moderator who did the action is the message author or, if used, the specified -mod
let mod = msg.member;
let pp = null;
let mod: Member = msg.member;
let pp: User | null = null;
if (args.mod) {
if (!hasPermission(pluginData, "can_act_as_other", { message: msg })) {
@ -36,7 +37,7 @@ export async function actualMuteUserCmd(
}
const timeUntilUnmute = args.time && humanizeDuration(args.time);
const reason = formatReasonWithAttachments(args.reason, msg.attachments);
const reason = args.reason ? formatReasonWithAttachments(args.reason, msg.attachments) : undefined;
let muteResult: MuteResult;
const mutesPlugin = pluginData.getPlugin(MutesPlugin);
@ -54,7 +55,7 @@ export async function actualMuteUserCmd(
contactMethods,
caseArgs: {
modId: mod.id,
ppId: pp && pp.id,
ppId: pp ? pp.id : undefined,
},
});
} catch (e) {

View file

@ -15,7 +15,7 @@ export async function actualUnmuteCmd(
) {
// The moderator who did the action is the message author or, if used, the specified -mod
let mod = msg.author;
let pp = null;
let pp: User | null = null;
if (args.mod) {
if (!hasPermission(pluginData, "can_act_as_other", { message: msg, channelId: msg.channel.id })) {
@ -27,15 +27,20 @@ export async function actualUnmuteCmd(
pp = msg.author;
}
const reason = formatReasonWithAttachments(args.reason, msg.attachments);
const reason = args.reason ? formatReasonWithAttachments(args.reason, msg.attachments) : undefined;
const mutesPlugin = pluginData.getPlugin(MutesPlugin);
const result = await mutesPlugin.unmuteUser(user.id, args.time, {
modId: mod.id,
ppId: pp && pp.id,
ppId: pp ? pp.id : undefined,
reason,
});
if (!result) {
sendErrorMessage(pluginData, msg.channel, "User is not muted!");
return;
}
// Confirm the action to the moderator
if (args.time) {
const timeUntilUnmute = args.time && humanizeDuration(args.time);

View file

@ -1,6 +1,13 @@
import { GuildPluginData } from "knub";
import { BanOptions, BanResult, IgnoredEventType, ModActionsPluginType } from "../types";
import { notifyUser, resolveUser, stripObjectToScalars, ucfirst, UserNotificationResult } from "../../../utils";
import {
createUserNotificationError,
notifyUser,
resolveUser,
stripObjectToScalars,
ucfirst,
UserNotificationResult,
} from "../../../utils";
import { User } from "eris";
import { renderTemplate } from "../../../templateFormatter";
import { getDefaultContactMethods } from "./getDefaultContactMethods";
@ -15,7 +22,7 @@ import { CaseTypes } from "../../../data/CaseTypes";
export async function banUserId(
pluginData: GuildPluginData<ModActionsPluginType>,
userId: string,
reason: string = null,
reason?: string,
banOptions: BanOptions = {},
): Promise<BanResult> {
const config = pluginData.config.get();
@ -30,15 +37,22 @@ export async function banUserId(
// Attempt to message the user *before* banning them, as doing it after may not be possible
let notifyResult: UserNotificationResult = { method: null, success: true };
if (reason && user instanceof User) {
const banMessage = await renderTemplate(config.ban_message, {
guildName: pluginData.guild.name,
reason,
});
const contactMethods = banOptions?.contactMethods
? banOptions.contactMethods
: getDefaultContactMethods(pluginData, "ban");
notifyResult = await notifyUser(user, banMessage, contactMethods);
if (contactMethods.length) {
if (config.ban_message) {
const banMessage = await renderTemplate(config.ban_message, {
guildName: pluginData.guild.name,
reason,
});
notifyResult = await notifyUser(user, banMessage, contactMethods);
} else {
notifyResult = createUserNotificationError("No ban message specified in config");
}
}
}
// (Try to) ban the user
@ -59,18 +73,19 @@ export async function banUserId(
}
// Create a case for this action
const modId = banOptions.caseArgs?.modId || pluginData.client.user.id;
const casesPlugin = pluginData.getPlugin(CasesPlugin);
const createdCase = await casesPlugin.createCase({
...(banOptions.caseArgs || {}),
userId,
modId: banOptions.caseArgs?.modId,
modId,
type: CaseTypes.Ban,
reason,
noteDetails: notifyResult.text ? [ucfirst(notifyResult.text)] : [],
});
// Log the action
const mod = await resolveUser(pluginData.client, banOptions.caseArgs?.modId);
const mod = await resolveUser(pluginData.client, modId);
pluginData.state.serverLogs.log(LogType.MEMBER_BAN, {
mod: stripObjectToScalars(mod),
user: stripObjectToScalars(user),

View file

@ -1,7 +1,14 @@
import { GuildPluginData } from "knub";
import { IgnoredEventType, KickOptions, KickResult, ModActionsPluginType } from "../types";
import { Member } from "eris";
import { notifyUser, resolveUser, stripObjectToScalars, ucfirst, UserNotificationResult } from "../../../utils";
import {
createUserNotificationError,
notifyUser,
resolveUser,
stripObjectToScalars,
ucfirst,
UserNotificationResult,
} from "../../../utils";
import { renderTemplate } from "../../../templateFormatter";
import { getDefaultContactMethods } from "./getDefaultContactMethods";
import { LogType } from "../../../data/LogType";
@ -15,7 +22,7 @@ import { CasesPlugin } from "../../Cases/CasesPlugin";
export async function kickMember(
pluginData: GuildPluginData<ModActionsPluginType>,
member: Member,
reason: string = null,
reason?: string,
kickOptions: KickOptions = {},
): Promise<KickResult> {
const config = pluginData.config.get();
@ -23,15 +30,22 @@ export async function kickMember(
// Attempt to message the user *before* kicking them, as doing it after may not be possible
let notifyResult: UserNotificationResult = { method: null, success: true };
if (reason) {
const kickMessage = await renderTemplate(config.kick_message, {
guildName: pluginData.guild.name,
reason,
});
const contactMethods = kickOptions?.contactMethods
? kickOptions.contactMethods
: getDefaultContactMethods(pluginData, "kick");
notifyResult = await notifyUser(member.user, kickMessage, contactMethods);
if (contactMethods.length) {
if (config.kick_message) {
const kickMessage = await renderTemplate(config.kick_message, {
guildName: pluginData.guild.name,
reason,
});
notifyResult = await notifyUser(member.user, kickMessage, contactMethods);
} else {
notifyResult = createUserNotificationError("No kick message specified in the config");
}
}
}
// Kick the user
@ -46,19 +60,21 @@ export async function kickMember(
};
}
const modId = kickOptions.caseArgs?.modId || pluginData.client.user.id;
// Create a case for this action
const casesPlugin = pluginData.getPlugin(CasesPlugin);
const createdCase = await casesPlugin.createCase({
...(kickOptions.caseArgs || {}),
userId: member.id,
modId: kickOptions.caseArgs?.modId,
modId,
type: CaseTypes.Kick,
reason,
noteDetails: notifyResult.text ? [ucfirst(notifyResult.text)] : [],
});
// Log the action
const mod = await resolveUser(pluginData.client, kickOptions.caseArgs?.modId);
const mod = await resolveUser(pluginData.client, modId);
pluginData.state.serverLogs.log(LogType.MEMBER_KICK, {
mod: stripObjectToScalars(mod),
user: stripObjectToScalars(member.user),

View file

@ -2,7 +2,14 @@ import { GuildPluginData } from "knub";
import { ModActionsPluginType, WarnOptions, WarnResult } from "../types";
import { Member } from "eris";
import { getDefaultContactMethods } from "./getDefaultContactMethods";
import { notifyUser, resolveUser, stripObjectToScalars, ucfirst } from "../../../utils";
import {
createUserNotificationError,
notifyUser,
resolveUser,
stripObjectToScalars,
ucfirst,
UserNotificationResult,
} from "../../../utils";
import { waitForReaction } from "knub/dist/helpers";
import { CasesPlugin } from "../../Cases/CasesPlugin";
import { CaseTypes } from "../../../data/CaseTypes";
@ -13,14 +20,19 @@ export async function warnMember(
member: Member,
reason: string,
warnOptions: WarnOptions = {},
): Promise<WarnResult | null> {
): Promise<WarnResult> {
const config = pluginData.config.get();
const warnMessage = config.warn_message.replace("{guildName}", pluginData.guild.name).replace("{reason}", reason);
const contactMethods = warnOptions?.contactMethods
? warnOptions.contactMethods
: getDefaultContactMethods(pluginData, "warn");
const notifyResult = await notifyUser(member.user, warnMessage, contactMethods);
let notifyResult: UserNotificationResult;
if (config.warn_message) {
const warnMessage = config.warn_message.replace("{guildName}", pluginData.guild.name).replace("{reason}", reason);
const contactMethods = warnOptions?.contactMethods
? warnOptions.contactMethods
: getDefaultContactMethods(pluginData, "warn");
notifyResult = await notifyUser(member.user, warnMessage, contactMethods);
} else {
notifyResult = createUserNotificationError("No warn message specified in config");
}
if (!notifyResult.success) {
if (warnOptions.retryPromptChannel && pluginData.guild.channels.has(warnOptions.retryPromptChannel.id)) {
@ -43,17 +55,19 @@ export async function warnMember(
}
}
const modId = warnOptions.caseArgs?.modId ?? pluginData.client.user.id;
const casesPlugin = pluginData.getPlugin(CasesPlugin);
const createdCase = await casesPlugin.createCase({
...(warnOptions.caseArgs || {}),
userId: member.id,
modId: warnOptions.caseArgs?.modId,
modId,
type: CaseTypes.Warn,
reason,
noteDetails: notifyResult.text ? [ucfirst(notifyResult.text)] : [],
});
const mod = await resolveUser(pluginData.client, warnOptions.caseArgs?.modId);
const mod = await resolveUser(pluginData.client, modId);
pluginData.state.serverLogs.log(LogType.MEMBER_WARN, {
mod: stripObjectToScalars(mod),
member: stripObjectToScalars(member, ["user", "roles"]),

View file

@ -98,9 +98,9 @@ export type BanResult =
export type WarnMemberNotifyRetryCallback = () => boolean | Promise<boolean>;
export interface WarnOptions {
caseArgs?: Partial<CaseArgs>;
contactMethods?: UserNotificationMethod[];
retryPromptChannel?: TextChannel;
caseArgs?: Partial<CaseArgs> | null;
contactMethods?: UserNotificationMethod[] | null;
retryPromptChannel?: TextChannel | null;
}
export interface KickOptions {