3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-14 22:05:01 +00:00

Start move to d.js

This commit is contained in:
Dark 2021-05-31 03:30:55 +02:00
parent a9e0466e33
commit 9fc045cd38
No known key found for this signature in database
GPG key ID: 384C4B4F5B1E25A8
17 changed files with 339 additions and 6317 deletions

View file

@ -1,7 +1,7 @@
import { MessageContent, MessageFile, User } from "eris";
import { createChunkedMessage, HOURS, isDiscordRESTError } from "../utils";
import { logger } from "../logger";
import Timeout = NodeJS.Timeout;
import { APIMessage, User } from "discord.js";
let dmsDisabled = false;
let dmsDisabledTimeout: Timeout;
@ -16,7 +16,7 @@ export class DMError extends Error {}
const error20026 = "The bot cannot currently send DMs";
export async function sendDM(user: User, content: MessageContent, source: string) {
export async function sendDM(user: User, content: string | APIMessage, source: string) {
if (dmsDisabled) {
throw new DMError(error20026);
}
@ -24,15 +24,10 @@ export async function sendDM(user: User, content: MessageContent, source: string
logger.debug(`Sending ${source} DM to ${user.id}`);
try {
const dmChannel = await user.getDMChannel();
if (!dmChannel) {
throw new DMError("Unable to open DM channel");
}
if (typeof content === "string") {
await createChunkedMessage(dmChannel, content);
await createChunkedMessage(user, content);
} else {
await dmChannel.createMessage(content);
await user.send(content);
}
} catch (e) {
if (isDiscordRESTError(e) && e.code === 20026) {