refactor(helpers): rename & replace deleteMessageByID() with deleteMessage() (#668)

* refactor(helpers): rename & replace deleteMessageByID() with deleteMessage()

* changes

* fix

* fix

* Update src/types/errors.ts
This commit is contained in:
ayntee
2021-03-13 11:47:53 -05:00
committed by GitHub
parent e9cbbbff7c
commit 2d0b96c1e2
4 changed files with 11 additions and 37 deletions
+8 -6
View File
@@ -1,25 +1,27 @@
import { botID } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { RequestManager } from "../../rest/request_manager.ts";
import { Message } from "../../structures/mod.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
import { delay } from "../../util/utils.ts";
/** Delete a message */
/** Delete a message with the channel id and message id only. */
export async function deleteMessage(
message: Message,
channelID: string,
messageID: string,
reason?: string,
delayMilliseconds = 0,
) {
if (message.author.id !== botID) {
// This needs to check the channels permission not the guild permission
const message = await cacheHandlers.get("messages", messageID);
if (message && message.author.id !== botID) {
await requireBotChannelPermissions(message.channelID, ["MANAGE_MESSAGES"]);
}
if (delayMilliseconds) await delay(delayMilliseconds);
const result = await RequestManager.delete(
endpoints.CHANNEL_MESSAGE(message.channelID, message.id),
endpoints.CHANNEL_MESSAGE(channelID, messageID),
{ reason },
);
@@ -1,25 +0,0 @@
import { cacheHandlers } from "../../cache.ts";
import { RequestManager } from "../../rest/request_manager.ts";
import { endpoints } from "../../util/constants.ts";
import { delay } from "../../util/utils.ts";
import { deleteMessage } from "./delete_message.ts";
/** Delete a message with the channel id and message id only. */
export async function deleteMessageByID(
channelID: string,
messageID: string,
reason?: string,
delayMilliseconds = 0,
) {
const message = await cacheHandlers.get("messages", messageID);
if (message) return deleteMessage(message, reason, delayMilliseconds);
if (delayMilliseconds) await delay(delayMilliseconds);
const result = await RequestManager.delete(
endpoints.CHANNEL_MESSAGE(channelID, messageID),
{ reason },
);
return result;
}