mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 20:35:02 +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
|
@ -12,7 +12,7 @@ export async function createCase(pluginData: GuildPluginData<CasesPluginType>, a
|
|||
const mod = await resolveUser(pluginData.client, args.modId);
|
||||
const modName = `${mod.username}#${mod.discriminator}`;
|
||||
|
||||
let ppName = null;
|
||||
let ppName: string | null = null;
|
||||
if (args.ppId) {
|
||||
const pp = await resolveUser(pluginData.client, args.ppId);
|
||||
ppName = `${pp.username}#${pp.discriminator}`;
|
||||
|
|
|
@ -15,7 +15,9 @@ export async function getCaseEmbed(
|
|||
requestMemberId?: string,
|
||||
): Promise<AdvancedMessageContent> {
|
||||
const theCase = await pluginData.state.cases.with("notes").find(resolveCaseId(caseOrCaseId));
|
||||
if (!theCase) return null;
|
||||
if (!theCase) {
|
||||
throw new Error("Unknown case");
|
||||
}
|
||||
|
||||
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
|
||||
|
||||
|
|
|
@ -28,12 +28,13 @@ export async function getCaseSummary(
|
|||
caseOrCaseId: Case | number,
|
||||
withLinks = false,
|
||||
requestMemberId?: string,
|
||||
) {
|
||||
): Promise<string | null> {
|
||||
const config = pluginData.config.get();
|
||||
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
|
||||
|
||||
const caseId = caseOrCaseId instanceof Case ? caseOrCaseId.id : caseOrCaseId;
|
||||
const theCase = await pluginData.state.cases.with("notes").find(caseId);
|
||||
if (!theCase) return null;
|
||||
|
||||
const firstNote = theCase.notes[0];
|
||||
let reason = firstNote ? firstNote.body : "";
|
||||
|
@ -47,7 +48,7 @@ export async function getCaseSummary(
|
|||
|
||||
if (reason.length > CASE_SUMMARY_REASON_MAX_LENGTH) {
|
||||
const match = reason.slice(CASE_SUMMARY_REASON_MAX_LENGTH, 100).match(/(?:[.,!?\s]|$)/);
|
||||
const nextWhitespaceIndex = match ? CASE_SUMMARY_REASON_MAX_LENGTH + match.index : CASE_SUMMARY_REASON_MAX_LENGTH;
|
||||
const nextWhitespaceIndex = match ? CASE_SUMMARY_REASON_MAX_LENGTH + match.index! : CASE_SUMMARY_REASON_MAX_LENGTH;
|
||||
if (nextWhitespaceIndex < reason.length) {
|
||||
reason = reason.slice(0, nextWhitespaceIndex - 1) + "...";
|
||||
}
|
||||
|
@ -56,7 +57,7 @@ export async function getCaseSummary(
|
|||
reason = disableLinkPreviews(reason);
|
||||
|
||||
const timestamp = moment.utc(theCase.created_at, DBDateFormat);
|
||||
const relativeTimeCutoff = convertDelayStringToMS(config.relative_time_cutoff);
|
||||
const relativeTimeCutoff = convertDelayStringToMS(config.relative_time_cutoff)!;
|
||||
const useRelativeTime = config.show_relative_times && Date.now() - timestamp.valueOf() < relativeTimeCutoff;
|
||||
const timestampWithTz = requestMemberId
|
||||
? await timeAndDate.inMemberTz(requestMemberId, timestamp)
|
||||
|
|
|
@ -11,13 +11,13 @@ import { logger } from "../../../logger";
|
|||
export async function postToCaseLogChannel(
|
||||
pluginData: GuildPluginData<CasesPluginType>,
|
||||
content: MessageContent,
|
||||
file: MessageFile = null,
|
||||
file?: MessageFile,
|
||||
): Promise<Message | null> {
|
||||
const caseLogChannelId = pluginData.config.get().case_log_channel;
|
||||
if (!caseLogChannelId) return;
|
||||
if (!caseLogChannelId) return null;
|
||||
|
||||
const caseLogChannel = pluginData.guild.channels.get(caseLogChannelId);
|
||||
if (!caseLogChannel || !(caseLogChannel instanceof TextChannel)) return;
|
||||
if (!caseLogChannel || !(caseLogChannel instanceof TextChannel)) return null;
|
||||
|
||||
let result;
|
||||
try {
|
||||
|
@ -30,7 +30,7 @@ export async function postToCaseLogChannel(
|
|||
pluginData.state.logs.log(LogType.BOT_ALERT, {
|
||||
body: `Missing permissions to post mod cases in <#${caseLogChannel.id}>`,
|
||||
});
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
throw e;
|
||||
|
@ -44,17 +44,17 @@ export async function postCaseToCaseLogChannel(
|
|||
caseOrCaseId: Case | number,
|
||||
): Promise<Message | null> {
|
||||
const theCase = await pluginData.state.cases.find(resolveCaseId(caseOrCaseId));
|
||||
if (!theCase) return;
|
||||
if (!theCase) return null;
|
||||
|
||||
const caseEmbed = await getCaseEmbed(pluginData, caseOrCaseId);
|
||||
if (!caseEmbed) return;
|
||||
if (!caseEmbed) return null;
|
||||
|
||||
if (theCase.log_message_id) {
|
||||
const [channelId, messageId] = theCase.log_message_id.split("-");
|
||||
|
||||
try {
|
||||
await pluginData.client.editMessage(channelId, messageId, caseEmbed);
|
||||
return;
|
||||
return null;
|
||||
} catch (e) {} // tslint:disable-line:no-empty
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue