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
|
@ -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