From aa39b1b62fbe4032cc25d4f2d72bf31dea660951 Mon Sep 17 00:00:00 2001 From: Skillz4Killz Date: Tue, 15 Dec 2020 17:57:02 -0500 Subject: [PATCH] fmt --- src/structures/channel.ts | 19 +++++++++++++------ src/structures/message.ts | 17 +++++++++++++++++ src/structures/role.ts | 36 ++++++++++++++++++++++++------------ src/utils/utils.ts | 4 ++-- 4 files changed, 56 insertions(+), 20 deletions(-) diff --git a/src/structures/channel.ts b/src/structures/channel.ts index 1be24fa20..4d4823a9f 100644 --- a/src/structures/channel.ts +++ b/src/structures/channel.ts @@ -1,6 +1,11 @@ import { Collection, createNewProp, Guild } from "../../mod.ts"; import { cacheHandlers } from "../controllers/cache.ts"; -import { ChannelCreatePayload, ChannelType, RawOverwrite, Unpromise } from "../types/types.ts"; +import { + ChannelCreatePayload, + ChannelType, + RawOverwrite, + Unpromise, +} from "../types/types.ts"; import { cache } from "../utils/cache.ts"; import { Message } from "./message.ts"; @@ -9,11 +14,11 @@ const baseChannel: any = { return cache.guilds.get(this.guildID); }, get messages() { - return cache.messages.filter(m => m.channelID === this.id); + return cache.messages.filter((m) => m.channelID === this.id); }, get mention() { return `<#${this.id}>`; - } + }, }; export async function createChannel( @@ -45,7 +50,9 @@ export async function createChannel( userLimit: createNewProp(userLimit), rateLimitPerUser: createNewProp(rateLimitPerUser), parentID: createNewProp(parentID || undefined), - lastPinTimestamp: createNewProp(lastPinTimestamp ? Date.parse(lastPinTimestamp) : undefined), + lastPinTimestamp: createNewProp( + lastPinTimestamp ? Date.parse(lastPinTimestamp) : undefined, + ), permissionOverwrites: createNewProp(permission_overwrites || []), nsfw: createNewProp(data.nsfw || false), }); @@ -83,7 +90,7 @@ export interface Channel { permissionOverwrites: RawOverwrite[]; /** Whether this channel is nsfw or not */ nsfw: boolean; - + // GETTERS /** @@ -100,4 +107,4 @@ export interface Channel { messages: Collection; /** The mention of the channel */ mention: string; -} \ No newline at end of file +} diff --git a/src/structures/message.ts b/src/structures/message.ts index 193ed9304..1b3263dca 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -1,4 +1,21 @@ import { MessageCreateOptions, Unpromise } from "../types/types.ts"; +import { cache } from "../utils/cache.ts"; + +const baseMessage: any = { + get guild() { + return cache.guilds.get(this.guildID); + }, + get member() { + return cache.members.get(this.authorID); + }, + get guildMember() { + return this.member.guilds.get(this.guildID); + }, + get link() { + return `https://discord.com/channels/${this.guildID || + "@me"}/${this.channelID}/${this.id}`; + }, +}; export async function createMessage(data: MessageCreateOptions) { const { diff --git a/src/structures/role.ts b/src/structures/role.ts index bbd61f50f..264cd7eb1 100644 --- a/src/structures/role.ts +++ b/src/structures/role.ts @@ -8,33 +8,42 @@ import { Member } from "./member.ts"; const baseRole: Partial = { get guild() { - return cache.guilds.find(g => g.roles.has(this.id)); + return cache.guilds.find((g) => g.roles.has(this.id)); }, get hexColor() { return this.color!.toString(16); }, get members() { - return cache.members.filter(m => m.guilds.some(g => g.roles.includes(this.id))); + return cache.members.filter((m) => + m.guilds.some((g) => g.roles.includes(this.id)) + ); }, get mention() { return `<@&${this.id}>`; }, - // METHODS delete: function (guildID?: string) { // If not guild id was provided try and find one if (!guildID) guildID = guildID || this.guild?.id; // If a guild id is still not available error out - if (!guildID) throw new Error("role.delete() did not find a valid guild in cache. Please provide the guildID like role.delete(guildID)") - + if (!guildID) { + throw new Error( + "role.delete() did not find a valid guild in cache. Please provide the guildID like role.delete(guildID)", + ); + } + return deleteRole(guildID, this.id!).catch(console.error); }, edit(options: CreateRoleOptions, guildID?: string) { // If not guild id was provided try and find one if (!guildID) guildID = guildID || this.guild?.id; // If a guild id is still not available error out - if (!guildID) throw new Error("role.edit() did not find a valid guild in cache. Please provide the guildID like role.edit({}, guildID)") + if (!guildID) { + throw new Error( + "role.edit() did not find a valid guild in cache. Please provide the guildID like role.edit({}, guildID)", + ); + } return editRole(guildID, this.id!, options); }, @@ -42,17 +51,20 @@ const baseRole: Partial = { // If no position try and find one from cache if (!position) position = this.guild?.roles.get(roleID)?.position; // If still none error out. - if (!position) throw new Error("role.higherThanRoleID() did not have a position provided and the role or guild was not found in cache. Please provide a position like role.higherThanRoleID(roleID, position)") - + if (!position) { + throw new Error( + "role.higherThanRoleID() did not have a position provided and the role or guild was not found in cache. Please provide a position like role.higherThanRoleID(roleID, position)", + ); + } + // Rare edge case handling if (this.position === position) { - return this.id! < roleID + return this.id! < roleID; } return this.position! > position; }, - -} +}; export async function createRole(data: RoleData) { const { tags, ...rest } = data; @@ -68,7 +80,7 @@ export async function createRole(data: RoleData) { botID: createNewProp(tags?.bot_id), isNitroBoostRole: createNewProp("premium_subscriber" in (tags ?? {})), integrationID: createNewProp(tags?.integration_id), - }) + }); return role as Role; } diff --git a/src/utils/utils.ts b/src/utils/utils.ts index b7bc025fd..1c70309d8 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -35,5 +35,5 @@ export async function urlToBase64(url: string) { /** Allows easy way to add a prop to a base object when needing to use complicated getters solution. */ export function createNewProp(value: any) { - return { configurable: true, enumerable: true, writable: true, value } -} \ No newline at end of file + return { configurable: true, enumerable: true, writable: true, value }; +}