Centralize DM logic, don't attempt DMs for an hour after a 20026 error

This commit is contained in:
Dragory 2020-08-21 03:44:38 +03:00
parent 1d4c32d8f9
commit 902be16ae8
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
5 changed files with 60 additions and 16 deletions

View file

@ -38,6 +38,8 @@ import moment from "moment-timezone";
import { SimpleCache } from "./SimpleCache";
import { logger } from "./logger";
import { unsafeCoerce } from "fp-ts/lib/function";
import { sendDM } from "./utils/sendDM";
import { LogType } from "./data/LogType";
const fsp = fs.promises;
@ -878,9 +880,7 @@ export async function notifyUser(
for (const method of methods) {
if (method.type === "dm") {
try {
console.log(`Notifying user ${user.id} via DM`);
const dmChannel = await user.getDMChannel();
await dmChannel.createMessage(body);
await sendDM(user, body, "mod action notification");
return {
method,
success: true,
@ -1069,8 +1069,6 @@ export async function resolveMember(bot: Client, guild: Guild, value: string): P
return null;
}
logger.debug(`Fetching unknown member (${userId} in ${guild.name} (${guild.id})) from the API`);
const freshMember = await bot.getRESTGuildMember(guild.id, userId).catch(noop);
if (freshMember) {
freshMember.id = userId;