mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-11 20:55:01 +00:00
Turn on strict TS compilation. Fix up and tweak types accordingly.
This commit is contained in:
parent
690955a399
commit
629002b8d9
172 changed files with 720 additions and 534 deletions
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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"]),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue