Prettified Code!

This commit is contained in:
itohatweb
2021-05-21 15:55:49 +00:00
committed by GitHub Action
parent 71a20fb0f4
commit 179add27c9
271 changed files with 889 additions and 3067 deletions
+10 -38
View File
@@ -13,10 +13,7 @@ import { snakelize, validateComponents } from "../../util/utils.ts";
import { validateLength } from "../../util/validate_length.ts";
/** Send a message to the channel. Requires SEND_MESSAGES permission. */
export async function sendMessage(
channelId: bigint,
content: string | CreateMessage
) {
export async function sendMessage(channelId: bigint, content: string | CreateMessage) {
if (typeof content === "string") content = { content };
const channel = await cacheHandlers.get("channels", channelId);
@@ -34,17 +31,11 @@ export async function sendMessage(
throw new Error(Errors.CHANNEL_NOT_TEXT_BASED);
}
const requiredPerms: Set<PermissionStrings> = new Set([
"SEND_MESSAGES",
"VIEW_CHANNEL",
]);
const requiredPerms: Set<PermissionStrings> = new Set(["SEND_MESSAGES", "VIEW_CHANNEL"]);
if (content.tts) requiredPerms.add("SEND_TTS_MESSAGES");
if (content.embed) requiredPerms.add("EMBED_LINKS");
if (
content.messageReference?.messageId ||
content.allowedMentions?.repliedUser
) {
if (content.messageReference?.messageId || content.allowedMentions?.repliedUser) {
requiredPerms.add("READ_MESSAGE_HISTORY");
}
@@ -58,40 +49,22 @@ export async function sendMessage(
if (content.allowedMentions) {
if (content.allowedMentions.users?.length) {
if (
content.allowedMentions.parse?.includes(
DiscordAllowedMentionsTypes.UserMentions
)
) {
content.allowedMentions.parse = content.allowedMentions.parse.filter(
(p) => p !== "users"
);
if (content.allowedMentions.parse?.includes(DiscordAllowedMentionsTypes.UserMentions)) {
content.allowedMentions.parse = content.allowedMentions.parse.filter((p) => p !== "users");
}
if (content.allowedMentions.users.length > 100) {
content.allowedMentions.users = content.allowedMentions.users.slice(
0,
100
);
content.allowedMentions.users = content.allowedMentions.users.slice(0, 100);
}
}
if (content.allowedMentions.roles?.length) {
if (
content.allowedMentions.parse?.includes(
DiscordAllowedMentionsTypes.RoleMentions
)
) {
content.allowedMentions.parse = content.allowedMentions.parse.filter(
(p) => p !== "roles"
);
if (content.allowedMentions.parse?.includes(DiscordAllowedMentionsTypes.RoleMentions)) {
content.allowedMentions.parse = content.allowedMentions.parse.filter((p) => p !== "roles");
}
if (content.allowedMentions.roles.length > 100) {
content.allowedMentions.roles = content.allowedMentions.roles.slice(
0,
100
);
content.allowedMentions.roles = content.allowedMentions.roles.slice(0, 100);
}
}
}
@@ -109,8 +82,7 @@ export async function sendMessage(
? {
messageReference: {
...content.messageReference,
failIfNotExists:
content.messageReference.failIfNotExists === true,
failIfNotExists: content.messageReference.failIfNotExists === true,
},
}
: {}),