From 2a27466a7efb2c202f1425922632cc965ef76420 Mon Sep 17 00:00:00 2001 From: Skillz4Killz Date: Tue, 15 Dec 2020 14:04:23 -0500 Subject: [PATCH 01/21] good for new contributors 2 use the same settings --- .gitignore | 3 --- .vscode/settings.json | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index aa7e0d962..b2b9fc9d2 100644 --- a/.gitignore +++ b/.gitignore @@ -12,8 +12,5 @@ dist/ public/ .cache/ -# Visual Studio Code -.vscode/ - # IntelliJ IDEA .idea/ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..24b5136ca --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "deno.enable": true, + +} \ No newline at end of file From 1a578d9fdcf17d03313330a4f62c0e4a3a7a5e05 Mon Sep 17 00:00:00 2001 From: Skillz4Killz Date: Tue, 15 Dec 2020 14:04:32 -0500 Subject: [PATCH 02/21] createNewProp --- src/utils/utils.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/utils/utils.ts b/src/utils/utils.ts index bacaf4c6c..b7bc025fd 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -32,3 +32,8 @@ export async function urlToBase64(url: string) { const type = url.substring(url.lastIndexOf(".") + 1); return `data:image/${type};base64,${imageStr}`; } + +/** 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 From dc9b0a78ec30d799c477baaef3659d2e21422b91 Mon Sep 17 00:00:00 2001 From: Skillz4Killz Date: Tue, 15 Dec 2020 14:53:28 -0500 Subject: [PATCH 03/21] channels with getters --- src/structures/channel.ts | 94 +++++++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 24 deletions(-) diff --git a/src/structures/channel.ts b/src/structures/channel.ts index fa3029636..9fd1f7cfd 100644 --- a/src/structures/channel.ts +++ b/src/structures/channel.ts @@ -1,5 +1,20 @@ +import { Collection, createNewProp, Guild } from "../../mod.ts"; import { cacheHandlers } from "../controllers/cache.ts"; -import { ChannelCreatePayload, Unpromise } from "../types/types.ts"; +import { ChannelCreatePayload, RawOverwrite, Unpromise } from "../types/types.ts"; +import { cache } from "../utils/cache.ts"; +import { Message } from "./message.ts"; + +const baseChannel: any = { + get guild() { + return cache.guilds.get(this.guildID); + }, + get messages() { + return cache.messages.filter(m => m.channelID === this.id); + }, + get mention() { + return `<#${this.id}>`; + } +}; export async function createChannel( data: ChannelCreatePayload, @@ -13,33 +28,64 @@ export async function createChannel( parent_id: parentID, last_pin_timestamp: lastPinTimestamp, permission_overwrites, + nsfw, ...rest } = data; - const channel = { - ...rest, - /** The guild id of the channel if it is a guild channel. */ - guildID: guildID || rawGuildID || "", - /** The id of the last message sent in this channel */ - lastMessageID, - /** The amount of users allowed in this voice channel. */ - userLimit, - /** The rate limit(slowmode) in this text channel that users can send messages. */ - rateLimitPerUser, - /** The category id for this channel */ - parentID, - /** The last time when a message was pinned in this channel */ - lastPinTimestamp, - /** The permission overwrites for this channel */ - permissionOverwrites: permission_overwrites, - /** Whether this channel is nsfw or not */ - nsfw: data.nsfw || false, - /** The mention of the channel */ - mention: `<#${data.id}>`, - }; + const restProps = {}; + for (const key of Object.keys(rest)) { + // @ts-ignore + restProps[key] = createNewProp(rest[key]); + } + + const channel = Object.create(baseChannel, { + ...restProps, + guildID: createNewProp(guildID || rawGuildID || ""), + lastMessageID: createNewProp(lastMessageID), + userLimit: createNewProp(userLimit), + rateLimitPerUser: createNewProp(rateLimitPerUser), + parentID: createNewProp(parentID || undefined), + lastPinTimestamp: createNewProp(lastPinTimestamp ? Date.parse(lastPinTimestamp) : undefined), + permissionOverwrites: createNewProp(permission_overwrites || []), + nsfw: createNewProp(data.nsfw || false), + }); cacheHandlers.set("channels", data.id, channel); - return channel; + return channel as Channel; } -export interface Channel extends Unpromise> {} +export interface Channel { + /** The guild id of the channel if it is a guild channel. */ + guildID: string; + /** The id of the last message sent in this channel */ + lastMessageID?: string; + /** The amount of users allowed in this voice channel. */ + userLimit?: number; + /** The rate limit(slowmode) in this text channel that users can send messages. */ + rateLimitPerUser?: number; + /** The category id for this channel */ + parentID?: string; + /** The last time when a message was pinned in this channel */ + lastPinTimestamp?: number; + /** The permission overwrites for this channel */ + permissionOverwrites: RawOverwrite[]; + /** Whether this channel is nsfw or not */ + nsfw: boolean; + + // GETTERS + + /** + * Gets the guild object for this channel. + * + * ⚠️ ADVANCED: If you use the custom cache, these will not work for you. Getters can not be async and custom cache requires async. + */ + guild?: Guild; + /** + * Gets the messages from cache that were sent in this channel + * + * ⚠️ ADVANCED: If you use the custom cache, these will not work for you. Getters can not be async and custom cache requires async. + */ + messages: Collection; + /** The mention of the channel */ + mention: string; +} \ No newline at end of file From e79e7af2cbf0baefc8d65b8879d3ce24011d85a5 Mon Sep 17 00:00:00 2001 From: Skillz4Killz Date: Tue, 15 Dec 2020 15:00:55 -0500 Subject: [PATCH 04/21] this is why i hate typings --- src/structures/channel.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/structures/channel.ts b/src/structures/channel.ts index 9fd1f7cfd..1be24fa20 100644 --- a/src/structures/channel.ts +++ b/src/structures/channel.ts @@ -1,6 +1,6 @@ import { Collection, createNewProp, Guild } from "../../mod.ts"; import { cacheHandlers } from "../controllers/cache.ts"; -import { ChannelCreatePayload, 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"; @@ -55,6 +55,18 @@ export async function createChannel( } export interface Channel { + /** The id of this channel */ + id: string; + /** Sorting position of the channel */ + position?: number; + /** The name of the channel (2-100 characters) */ + name?: string; + /** The channel topic (0-1024 characters) */ + topic?: string; + /** The bitrate (in bits) of the voice channel */ + bitrate?: number; + /** The type of the channel */ + type: ChannelType; /** The guild id of the channel if it is a guild channel. */ guildID: string; /** The id of the last message sent in this channel */ From 6da69658780f704eb4674f5f01b2597fdd2d49ae Mon Sep 17 00:00:00 2001 From: Skillz4Killz Date: Tue, 15 Dec 2020 15:32:14 -0500 Subject: [PATCH 05/21] role getters --- src/structures/role.ts | 68 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 13 deletions(-) diff --git a/src/structures/role.ts b/src/structures/role.ts index 51ace0370..a7f83baa1 100644 --- a/src/structures/role.ts +++ b/src/structures/role.ts @@ -1,20 +1,62 @@ -import { RoleData, Unpromise } from "../types/types.ts"; +import { Permission, RoleData, Unpromise } from "../types/types.ts"; +import { createNewProp } from "../utils/utils.ts"; + +const baseRole: any = { + get hexColor() { + return this.color.toString(16); + }, + get mention() { + return `<@&${this.id}>`; + } +} export async function createRole(data: RoleData) { const { tags, ...rest } = data; - const roleTags = { - botID: tags?.bot_id, - premiumSubscriber: "premium_subscriber" in (tags ?? {}), - integrationID: tags?.integration_id, - }; + const restProps = {}; + for (const key of Object.keys(rest)) { + // @ts-ignore + restProps[key] = createNewProp(rest[key]); + } - return { - ...rest, - /** The @ mention of the role in a string. */ - mention: `<@&${data.id}>`, - tags: roleTags, - }; + const role = Object.create(baseRole, { + ...restProps, + botID: createNewProp(tags?.bot_id), + isNitroBoostRole: createNewProp("premium_subscriber" in (tags ?? {})), + integrationID: createNewProp(tags?.integration_id), + }) + + return role as Role; } -export interface Role extends Unpromise> {} +export interface Role { + /** role id */ + id: string; + /** role name */ + name: string; + /** integer representation of hexadecimal color code */ + color: number; + /** if this role is pinned in the user listing */ + hoist: boolean; + /** position of this role */ + position: number; + /** permission bit set */ + permissions: string; + /** whether this role is managed by an integration */ + managed: boolean; + /** whether this role is mentionable */ + mentionable: boolean; + /** The bot id that is associated with this role. */ + botID?: string; + /** If this role is the nitro boost role. */ + isNitroBoostRole: boolean; + /** The integration id that is associated with this role */ + integrationID: string; + + // GETTERS + + /** The hex color for this role. */ + hexColor: string; + /** The @ mention of the role in a string. */ + mention: string; +} From 7559ad68cccdc896a62dbd15101299469fc7c485 Mon Sep 17 00:00:00 2001 From: Skillz4Killz Date: Tue, 15 Dec 2020 17:52:19 -0500 Subject: [PATCH 06/21] nuke this bug --- src/utils/permissions.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/utils/permissions.ts b/src/utils/permissions.ts index 5c968fb67..9b9ed6664 100644 --- a/src/utils/permissions.ts +++ b/src/utils/permissions.ts @@ -244,9 +244,6 @@ export async function higherRolePosition( const guild = await cacheHandlers.get("guilds", guildID); if (!guild) return; - // If the bot is the owner of the guild, higher-role-checking is not necessary. - if (guild.ownerID === botID) return true; - const role = guild.roles.get(roleID); const otherRole = guild.roles.get(otherRoleID); if (!role || !otherRole) return; From 2f14cf75ac020ec5adb33fcc6b91637a6f19e5f0 Mon Sep 17 00:00:00 2001 From: Skillz4Killz Date: Tue, 15 Dec 2020 17:52:58 -0500 Subject: [PATCH 07/21] role stuff --- src/structures/role.ts | 65 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/src/structures/role.ts b/src/structures/role.ts index a7f83baa1..bbd61f50f 100644 --- a/src/structures/role.ts +++ b/src/structures/role.ts @@ -1,13 +1,57 @@ -import { Permission, RoleData, Unpromise } from "../types/types.ts"; +import { deleteRole, editRole } from "../handlers/guild.ts"; +import { CreateRoleOptions, RoleData } from "../types/types.ts"; +import { cache } from "../utils/cache.ts"; +import { Collection } from "../utils/collection.ts"; import { createNewProp } from "../utils/utils.ts"; +import { Guild } from "./guild.ts"; +import { Member } from "./member.ts"; -const baseRole: any = { +const baseRole: Partial = { + get guild() { + return cache.guilds.find(g => g.roles.has(this.id)); + }, get hexColor() { - return this.color.toString(16); + return this.color!.toString(16); + }, + get members() { + 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)") + + 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)") + + return editRole(guildID, this.id!, options); + }, + higherThanRoleID(roleID: string, position?: number) { + // 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)") + + // Rare edge case handling + if (this.position === position) { + return this.id! < roleID + } + + return this.position! > position; + }, + } export async function createRole(data: RoleData) { @@ -55,8 +99,21 @@ export interface Role { // GETTERS + /** The guild where this role is. If undefined, the guild is not cached */ + guild?: Guild; /** The hex color for this role. */ hexColor: string; + /** The cached members that have this role */ + members: Collection; /** The @ mention of the role in a string. */ mention: string; + + // METHODS + + /** Delete the role */ + delete(guildID?: string): Promise; + /** Edits the role */ + edit(options: CreateRoleOptions): Promise; + /** Checks if this role is higher than another role. */ + higherThanRoleID(roleID: string, position?: number): boolean; } From aa39b1b62fbe4032cc25d4f2d72bf31dea660951 Mon Sep 17 00:00:00 2001 From: Skillz4Killz Date: Tue, 15 Dec 2020 17:57:02 -0500 Subject: [PATCH 08/21] 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 }; +} From 370f3973443decf94e85184ddac650aff1d2f89a Mon Sep 17 00:00:00 2001 From: Skillz4Killz Date: Tue, 15 Dec 2020 18:06:16 -0500 Subject: [PATCH 09/21] fix the bugs my nuke opened --- src/handlers/member.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/handlers/member.ts b/src/handlers/member.ts index 52911e28d..f58850c2d 100644 --- a/src/handlers/member.ts +++ b/src/handlers/member.ts @@ -62,7 +62,10 @@ export async function addRole( botsHighestRole.id, roleID, ); - if (!hasHigherRolePosition) { + if ( + !hasHigherRolePosition && + (await cacheHandlers.get("guilds", guildID))?.ownerID !== botID + ) { throw new Error(Errors.BOTS_HIGHEST_ROLE_TOO_LOW); } } @@ -93,7 +96,10 @@ export async function removeRole( botsHighestRole.id, roleID, ); - if (!hasHigherRolePosition) { + if ( + !hasHigherRolePosition && + (await cacheHandlers.get("guilds", guildID))?.ownerID !== botID + ) { throw new Error(Errors.BOTS_HIGHEST_ROLE_TOO_LOW); } } From a65a6e3bdee3f096b8ab564c7872deee7791f320 Mon Sep 17 00:00:00 2001 From: Skillz4Killz Date: Wed, 16 Dec 2020 12:24:22 -0500 Subject: [PATCH 10/21] messages are annoying --- src/structures/message.ts | 204 ++++++++++++++++++++++++++++++++++---- 1 file changed, 183 insertions(+), 21 deletions(-) diff --git a/src/structures/message.ts b/src/structures/message.ts index 1b3263dca..f0c8a26dd 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -1,20 +1,82 @@ -import { MessageCreateOptions, Unpromise } from "../types/types.ts"; +import { Channel } from "../../mod.ts"; +import { sendMessage } from "../handlers/channel.ts"; +import { addReaction, addReactions, deleteMessageByID, editMessage, pin, removeAllReactions, removeReaction, removeReactionEmoji } from "../handlers/message.ts"; +import { Activity, Application, Attachment, Embed, GuildMember, MessageContent, MessageCreateOptions, MessageSticker, Reaction, Reference, Unpromise, UserPayload } from "../types/types.ts"; import { cache } from "../utils/cache.ts"; +import { createNewProp } from "../utils/utils.ts"; +import { Guild } from "./guild.ts"; +import { Member } from "./member.ts"; +import { Role } from "./role.ts"; -const baseMessage: any = { +const baseMessage: Partial = { get guild() { return cache.guilds.get(this.guildID); }, get member() { - return cache.members.get(this.authorID); + return cache.members.get(this.author?.id); }, get guildMember() { - return this.member.guilds.get(this.guildID); + return this.member?.guilds.get(this.guildID); }, get link() { return `https://discord.com/channels/${this.guildID || "@me"}/${this.channelID}/${this.id}`; }, + get mentionedRoles() { + return this.mentionRoleIDs?.map(id => this.guild?.roles.get(id)) || []; + }, + get mentionedChannels() { + return this.mentionChannelIDs?.map(id => cache.channels.get(id)) || []; + }, + get mentionedMembers() { + return this.mentions?.map(id => cache.members.get(id)) || [] + }, + + // METHODS + delete(reason, delayMilliseconds) { + return deleteMessageByID(this.channelID!, this.id!, reason, delayMilliseconds); + }, + edit(content) { + return editMessage(this, content); + }, + pin() { + return pin(this.channelID!, this.id!) + }, + addReaction(reaction) { + return addReaction(this.channelID!, this.id!, reaction); + }, + addReactions(reactions, ordered) { + return addReactions(this.channelID!, this.id!, reactions, ordered); + }, + sendResponse(content) { + const contentWithMention = typeof content === "string" + ? { content, mentions: { repliedUser: true }, replyMessageID: this.id } + : { + ...content, + mentions: { ...(content.mentions || {}), repliedUser: true }, + replyMessageID: this.id, + }; + + return sendMessage(this.channelID!, contentWithMention); + }, + reply(content) { + return sendMessage(this.channelID!, content); + }, + alert(content, timeout = 10, reason = "") { + return sendMessage(this.channelID!, content).then(response => response.delete(reason, timeout * 1000).catch(console.error)) + }, + alertResponse(content, timeout = 10, reason = "") { + return this.sendResponse!(content).then(response => response.delete(reason, timeout * 1000).catch(console.error)) + }, + removeAllReactions() { + return removeAllReactions(this.channelID!, this.id!); + }, + removeReactionEmoji(reaction) { + return removeReactionEmoji(this.channelID!, this.id!, reaction); + }, + removeReaction(reaction) { + return removeReaction(this.channelID!, this.id!, reaction); + }, }; export async function createMessage(data: MessageCreateOptions) { @@ -22,8 +84,8 @@ export async function createMessage(data: MessageCreateOptions) { guild_id: guildID, channel_id: channelID, mentions_everyone: mentionsEveryone, - mention_channels: mentionChannels, - mention_roles: mentionRoles, + mention_channels: mentionChannelIDs, + mention_roles: mentionRoleIDs, webhook_id: webhookID, message_reference: messageReference, edited_timestamp: editedTimestamp, @@ -31,23 +93,123 @@ export async function createMessage(data: MessageCreateOptions) { ...rest } = data; - const message = { - ...rest, + const restProps = {}; + for (const key of Object.keys(rest)) { + // @ts-ignore + restProps[key] = createNewProp(rest[key]); + } + + const message = Object.create(baseMessage, { + ...restProps, /** The message id of the original message if this message was sent as a reply. If null, the original message was deleted. */ - referencedMessageID, - channelID, - guildID: guildID || "", - mentions: data.mentions.map((m) => m.id), - mentionsEveryone, - mentionRoles, - mentionChannels: mentionChannels || [], - webhookID, - messageReference, - timestamp: Date.parse(data.timestamp), - editedTimestamp: editedTimestamp ? Date.parse(editedTimestamp) : undefined, - }; + referencedMessageID: createNewProp(referencedMessageID), + channelID: createNewProp(channelID), + guildID: createNewProp(guildID || ""), + mentions: createNewProp(data.mentions.map((m) => m.id)), + mentionsEveryone: createNewProp(mentionsEveryone), + mentionRoleIDs: createNewProp(mentionRoleIDs), + mentionChannelIDs: createNewProp(mentionChannelIDs?.map(m => m.id) || []), + webhookID: createNewProp(webhookID), + messageReference: createNewProp(messageReference), + timestamp: createNewProp(Date.parse(data.timestamp)), + editedTimestamp: createNewProp(editedTimestamp ? Date.parse(editedTimestamp) : undefined), + }); return message; } -export interface Message extends Unpromise> {} +export interface Message { + /** The id of the message */ + id: string; + /** The id of the channel the message was sent in */ + channelID: string; + /** The id of the guild the message was sent in */ + guildID: string; + /** The author of this message (not guaranteed to be a valid user such as a webhook.) */ + author: UserPayload; + /** The contents of the message */ + content: string; + /** When this message was sent */ + timestamp: string; + /** When this message was edited (if it was not edited, null) */ + editedTimestamp?: string; + /** Whether this was a TextToSpeech message. */ + tts: boolean; + /** Whether this message mentions everyone */ + mentionsEveryone: boolean; + /** Users specifically mentioned in the message. */ + mentions: string[]; + /** Roles specifically mentioned in this message */ + mentionRoleIDs: string[]; + /** Channels specifically mentioned in this message */ + mentionChannelIDs: string[]; + /** Any attached files */ + attachments: Attachment[]; + /** Any embedded content */ + embeds: Embed[]; + /** Reactions to the message */ + reactions?: Reaction[]; + /** Used for validating a message was sent */ + nonce?: number | string; + /** Whether this message is pinned */ + pinned: boolean; + /** If the message is generated by a webhook, this is the webhooks id */ + webhook_id?: string; + /** The type of message */ + type: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12; + /** The activities sent with Rich Presence-related chat embeds. */ + activity?: Activity; + /** Applications that sent with Rich Presence related chat embeds. */ + applications?: Application; + /** The reference data sent with crossposted messages */ + messageReference?: Reference; + /** The message flags combined like permission bits describe extra features of the message */ + flags?: 1 | 2 | 4 | 8 | 16; + /** the stickers sent with the message (bots currently can only receive messages with stickers, not send) */ + stickers?: MessageSticker[]; + /** The message id of the original message if this message was sent as a reply. If null, the original message was deleted. */ + referencedMessageID?: MessageCreateOptions | null; + + // GETTERS + /** The guild of this message. Can be undefined if not in cache or in DM */ + guild?: Guild; + /** The member for the user who sent the message. Can be undefined if not in cache or in dm. */ + member?: Member; + /** The guild member details for this guild and member. Can be undefined if not in cache or in dm. */ + guildMember?: GuildMember; + /** The url link to this message */ + link: string; + /** The role objects for all the roles that were mentioned in this message */ + mentionedRoles: Role[]; + /** The channel objects for all the channels that were mentioned in this message. */ + mentionedChannels: Channel[]; + /** The member objects for all the members that were mentioned in this message. */ + mentionedMembers: Member[]; + + // METHODS + + /** Delete the message */ + delete(reason?: string, delayMilliseconds?: number): Promise; + /** Edit the message */ + edit(content: string | MessageContent): Promise; + /** Pins the message in the channel */ + pin(): Promise; + /** Add a reaction to the message */ + addReaction(reaction: string): Promise; + /** Add multiple reactions to the message without or without order. */ + addReactions(reactions: string[], ordered?: boolean): Promise; + /** Send a inline reply to this message */ + sendResponse(content: string | MessageContent): Promise; + /** Send a message to this channel where this message is */ + reply(content: string | MessageContent): Promise; + /** Send a message to this channel and then delete it after a bit. By default it will delete after 10 seconds with no reason provided. */ + alert(content: string | MessageContent, timeout?: number, reason?: string): Promise; + /** Send a inline reply to this message but then delete it after a bit. By default it will delete after 10 seconds with no reason provided. */ + alertResponse(content: string | MessageContent, timeout?: number, reason?: string): Promise; + /** Remove all reactions */ + removeAllReactions(): Promise; + /** Remove all reactions */ + removeReactionEmoji(reaction: string): Promise; + /** Remove all reactions */ + removeReaction(reaction: string): Promise; +} \ No newline at end of file From c910c381a00e591610a8292ab097c00298119b92 Mon Sep 17 00:00:00 2001 From: Skillz4Killz Date: Wed, 16 Dec 2020 13:46:36 -0500 Subject: [PATCH 11/21] please work i hope --- src/structures/member.ts | 117 +++++++++++++++++++++++++++++++++++---- 1 file changed, 105 insertions(+), 12 deletions(-) diff --git a/src/structures/member.ts b/src/structures/member.ts index a85ae2c37..9f26e5b91 100644 --- a/src/structures/member.ts +++ b/src/structures/member.ts @@ -1,6 +1,43 @@ import { cacheHandlers } from "../controllers/cache.ts"; -import { GuildMember, MemberCreatePayload, Unpromise } from "../types/types.ts"; +import { ban } from "../handlers/guild.ts"; +import { addRole, editMember, kick, removeRole, sendDirectMessage } from "../handlers/member.ts"; +import { BanOptions, EditMemberOptions, GuildMember, MemberCreatePayload, MessageContent, Unpromise } from "../types/types.ts"; +import { cache } from "../utils/cache.ts"; import { Collection } from "../utils/collection.ts"; +import { createNewProp } from "../utils/utils.ts"; +import { Guild } from "./guild.ts"; + +const baseMember: Partial = { + // METHODS + + guild(guildID) { + return cache.guilds.get(guildID); + }, + name(guildID) { + return this.guildMember!(guildID)?.nick || this.username!; + }, + guildMember(guildID) { + return this.guilds?.get(guildID) + }, + sendDM(content) { + return sendDirectMessage(this.id!, content); + }, + kick(guildID, reason) { + return kick(guildID, this.id!, reason) + }, + edit(guildID, options) { + return editMember(guildID, this.id!, options) + }, + ban(guildID, options) { + return ban(guildID, this.id!, options); + }, + addRole(guildID, roleID, reason) { + return addRole(guildID, this.id!, roleID, reason); + }, + removeRole(guildID, roleID, reason) { + return removeRole(guildID, this.id!, roleID, reason); + }, +} export async function createMember(data: MemberCreatePayload, guildID: string) { const { @@ -20,17 +57,25 @@ export async function createMember(data: MemberCreatePayload, guildID: string) { ...user } = data.user || {}; - const member = { - ...rest, - // Only use those that we have not removed above - ...user, - /** Whether or not this user has 2FA enabled. */ - mfaEnabled, - /** The premium type for this user */ - premiumType, + const restProps = {}; + for (const key of Object.keys(rest)) { + // @ts-ignore + restProps[key] = createNewProp(rest[key]); + } + + for (const key of Object.keys(user)) { + // @ts-ignore + restProps[key] = createNewProp(user[key]); + } + + const member = Object.create(baseMember, { + // INCASE DISCORD ADDS MORE DATA USERS OF OUR LIB GET IT INSTANTLY + ...restProps, + mfaEnabled: createNewProp(mfaEnabled), + premiumType: createNewProp(premiumType), /** The guild related data mapped by guild id */ - guilds: new Collection(), - }; + guilds: createNewProp(new Collection()), + }); const cached = await cacheHandlers.get("members", user.id); if (cached) { @@ -54,4 +99,52 @@ export async function createMember(data: MemberCreatePayload, guildID: string) { return member; } -export interface Member extends Unpromise> {} +export interface Member { + /** The user's id */ + id: string; + /** the user's username, not unique across the platform */ + username: string; + /** The user's 4 digit discord tag */ + discriminator: string; + /** The user's avatar hash */ + avatar: string | null; + /** Whether the user is a bot */ + bot?: boolean; + /** Whether the user is an official discord system user (part of the urgent message system.) */ + system?: boolean; + /** the user's chosen language option */ + locale?: string; + /** Whether the email on this account has been verified */ + verified?: boolean; + /** The user's email */ + email?: string; + /** The flags on a user's account. */ + flags?: number; + /** Whether or not this user has 2FA enabled. */ + mfaEnabled?: boolean; + /** The premium type for this user */ + premiumType?: number; + /** The guild related data mapped by guild id */ + guilds: Collection; + + // METHODS + + /** Returns the guild for this guildID */ + guild(guildID: string): Guild | undefined; + /** Get the nickname or the username if no nickname */ + name(guildID: string): string; + /** Get the nickname */ + guildMember(guildID: string): GuildMember; + /** Send a direct message to the user is possible */ + sendDM(content: string | MessageContent): Promise; + /** Kick the member from a guild */ + kick(guildID: string, reason?: string): Promise; + /** Edit the member in a guild */ + edit(guildID: string, options: EditMemberOptions): Promise; + /** Ban a member in a guild */ + ban(guildID: string, options: BanOptions): Promise; + /** Add a role to the member */ + addRole(guildID: string, roleID: string, reason?: string): Promise; + /** Remove a role from the member */ + removeRole(guildID: string, roleID: string, reason?: string): Promise; +} From 01fc00334e953d0dddf14034c2d19cbc1b800d0b Mon Sep 17 00:00:00 2001 From: ayntee Date: Sat, 19 Dec 2020 13:19:39 +0400 Subject: [PATCH 12/21] fix: Member#guildMember return type --- src/structures/member.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/member.ts b/src/structures/member.ts index 9f26e5b91..d29a2a61a 100644 --- a/src/structures/member.ts +++ b/src/structures/member.ts @@ -134,7 +134,7 @@ export interface Member { /** Get the nickname or the username if no nickname */ name(guildID: string): string; /** Get the nickname */ - guildMember(guildID: string): GuildMember; + guildMember(guildID: string): GuildMember | undefined; /** Send a direct message to the user is possible */ sendDM(content: string | MessageContent): Promise; /** Kick the member from a guild */ From e082a5d69363bc79ee85a75003d203471c2312da Mon Sep 17 00:00:00 2001 From: ayntee Date: Sat, 19 Dec 2020 13:24:38 +0400 Subject: [PATCH 13/21] fix: check if Message#guildID is present --- src/structures/message.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/structures/message.ts b/src/structures/message.ts index f0c8a26dd..75ccbc7d8 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -10,12 +10,15 @@ import { Role } from "./role.ts"; const baseMessage: Partial = { get guild() { + if (!this.guildID) return; return cache.guilds.get(this.guildID); }, get member() { + if (!this.author?.id) return; return cache.members.get(this.author?.id); }, get guildMember() { + if (!this.guildID) return; return this.member?.guilds.get(this.guildID); }, get link() { @@ -37,7 +40,7 @@ const baseMessage: Partial = { return deleteMessageByID(this.channelID!, this.id!, reason, delayMilliseconds); }, edit(content) { - return editMessage(this, content); + return editMessage(this as Message, content); }, pin() { return pin(this.channelID!, this.id!) @@ -171,6 +174,7 @@ export interface Message { referencedMessageID?: MessageCreateOptions | null; // GETTERS + /** The guild of this message. Can be undefined if not in cache or in DM */ guild?: Guild; /** The member for the user who sent the message. Can be undefined if not in cache or in dm. */ @@ -180,11 +184,11 @@ export interface Message { /** The url link to this message */ link: string; /** The role objects for all the roles that were mentioned in this message */ - mentionedRoles: Role[]; + mentionedRoles: (Role | undefined)[]; /** The channel objects for all the channels that were mentioned in this message. */ - mentionedChannels: Channel[]; + mentionedChannels: (Channel | undefined)[]; /** The member objects for all the members that were mentioned in this message. */ - mentionedMembers: Member[]; + mentionedMembers: (Member | undefined)[]; // METHODS From d08adff0dd643b5206779304e73f421f11976f38 Mon Sep 17 00:00:00 2001 From: ayntee Date: Sat, 19 Dec 2020 13:52:48 +0400 Subject: [PATCH 14/21] feat: add getters for Template --- .vscode/settings.json | 6 +++- src/structures/channel.ts | 1 - src/structures/guild.ts | 8 ++--- src/structures/member.ts | 26 ++++++++++---- src/structures/message.ts | 73 +++++++++++++++++++++++++++++--------- src/structures/mod.ts | 5 +-- src/structures/template.ts | 67 +++++++++++++++++++++++++++------- src/types/misc.ts | 3 -- src/utils/utils.ts | 2 +- 9 files changed, 141 insertions(+), 50 deletions(-) delete mode 100644 src/types/misc.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 24b5136ca..8b3b2fa17 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,8 @@ { "deno.enable": true, - + "editor.defaultFormatter": "denoland.vscode-deno", + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.organizeImports": true + } } \ No newline at end of file diff --git a/src/structures/channel.ts b/src/structures/channel.ts index 4d4823a9f..545a341b7 100644 --- a/src/structures/channel.ts +++ b/src/structures/channel.ts @@ -4,7 +4,6 @@ import { ChannelCreatePayload, ChannelType, RawOverwrite, - Unpromise, } from "../types/types.ts"; import { cache } from "../utils/cache.ts"; import { Message } from "./message.ts"; diff --git a/src/structures/guild.ts b/src/structures/guild.ts index f0c9ab4aa..ced66d717 100644 --- a/src/structures/guild.ts +++ b/src/structures/guild.ts @@ -1,8 +1,4 @@ -import { - CreateGuildPayload, - MemberCreatePayload, - Unpromise, -} from "../types/types.ts"; +import { CreateGuildPayload, MemberCreatePayload } from "../types/types.ts"; import { Collection } from "../utils/collection.ts"; import { structures } from "./mod.ts"; @@ -99,4 +95,4 @@ export async function createGuild(data: CreateGuildPayload, shardID: number) { return guild; } -export interface Guild extends Unpromise> {} +export interface Guild {} diff --git a/src/structures/member.ts b/src/structures/member.ts index d29a2a61a..c4dc53cbc 100644 --- a/src/structures/member.ts +++ b/src/structures/member.ts @@ -1,7 +1,19 @@ import { cacheHandlers } from "../controllers/cache.ts"; import { ban } from "../handlers/guild.ts"; -import { addRole, editMember, kick, removeRole, sendDirectMessage } from "../handlers/member.ts"; -import { BanOptions, EditMemberOptions, GuildMember, MemberCreatePayload, MessageContent, Unpromise } from "../types/types.ts"; +import { + addRole, + editMember, + kick, + removeRole, + sendDirectMessage, +} from "../handlers/member.ts"; +import { + BanOptions, + EditMemberOptions, + GuildMember, + MemberCreatePayload, + MessageContent, +} from "../types/types.ts"; import { cache } from "../utils/cache.ts"; import { Collection } from "../utils/collection.ts"; import { createNewProp } from "../utils/utils.ts"; @@ -17,16 +29,16 @@ const baseMember: Partial = { return this.guildMember!(guildID)?.nick || this.username!; }, guildMember(guildID) { - return this.guilds?.get(guildID) + return this.guilds?.get(guildID); }, sendDM(content) { return sendDirectMessage(this.id!, content); }, kick(guildID, reason) { - return kick(guildID, this.id!, reason) + return kick(guildID, this.id!, reason); }, edit(guildID, options) { - return editMember(guildID, this.id!, options) + return editMember(guildID, this.id!, options); }, ban(guildID, options) { return ban(guildID, this.id!, options); @@ -37,7 +49,7 @@ const baseMember: Partial = { removeRole(guildID, roleID, reason) { return removeRole(guildID, this.id!, roleID, reason); }, -} +}; export async function createMember(data: MemberCreatePayload, guildID: string) { const { @@ -128,7 +140,7 @@ export interface Member { guilds: Collection; // METHODS - + /** Returns the guild for this guildID */ guild(guildID: string): Guild | undefined; /** Get the nickname or the username if no nickname */ diff --git a/src/structures/message.ts b/src/structures/message.ts index 75ccbc7d8..c502dc683 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -1,7 +1,28 @@ import { Channel } from "../../mod.ts"; import { sendMessage } from "../handlers/channel.ts"; -import { addReaction, addReactions, deleteMessageByID, editMessage, pin, removeAllReactions, removeReaction, removeReactionEmoji } from "../handlers/message.ts"; -import { Activity, Application, Attachment, Embed, GuildMember, MessageContent, MessageCreateOptions, MessageSticker, Reaction, Reference, Unpromise, UserPayload } from "../types/types.ts"; +import { + addReaction, + addReactions, + deleteMessageByID, + editMessage, + pin, + removeAllReactions, + removeReaction, + removeReactionEmoji, +} from "../handlers/message.ts"; +import { + Activity, + Application, + Attachment, + Embed, + GuildMember, + MessageContent, + MessageCreateOptions, + MessageSticker, + Reaction, + Reference, + UserPayload, +} from "../types/types.ts"; import { cache } from "../utils/cache.ts"; import { createNewProp } from "../utils/utils.ts"; import { Guild } from "./guild.ts"; @@ -26,24 +47,30 @@ const baseMessage: Partial = { "@me"}/${this.channelID}/${this.id}`; }, get mentionedRoles() { - return this.mentionRoleIDs?.map(id => this.guild?.roles.get(id)) || []; + // TODO: add getters for Guild structure, that will fix this error + return this.mentionRoleIDs?.map((id) => this.guild?.roles.get(id)) || []; }, get mentionedChannels() { - return this.mentionChannelIDs?.map(id => cache.channels.get(id)) || []; + return this.mentionChannelIDs?.map((id) => cache.channels.get(id)) || []; }, get mentionedMembers() { - return this.mentions?.map(id => cache.members.get(id)) || [] + return this.mentions?.map((id) => cache.members.get(id)) || []; }, // METHODS delete(reason, delayMilliseconds) { - return deleteMessageByID(this.channelID!, this.id!, reason, delayMilliseconds); + return deleteMessageByID( + this.channelID!, + this.id!, + reason, + delayMilliseconds, + ); }, edit(content) { return editMessage(this as Message, content); }, pin() { - return pin(this.channelID!, this.id!) + return pin(this.channelID!, this.id!); }, addReaction(reaction) { return addReaction(this.channelID!, this.id!, reaction); @@ -59,17 +86,21 @@ const baseMessage: Partial = { mentions: { ...(content.mentions || {}), repliedUser: true }, replyMessageID: this.id, }; - + return sendMessage(this.channelID!, contentWithMention); }, reply(content) { return sendMessage(this.channelID!, content); }, alert(content, timeout = 10, reason = "") { - return sendMessage(this.channelID!, content).then(response => response.delete(reason, timeout * 1000).catch(console.error)) + return sendMessage(this.channelID!, content).then((response) => + response.delete(reason, timeout * 1000).catch(console.error) + ); }, alertResponse(content, timeout = 10, reason = "") { - return this.sendResponse!(content).then(response => response.delete(reason, timeout * 1000).catch(console.error)) + return this.sendResponse!(content).then((response) => + response.delete(reason, timeout * 1000).catch(console.error) + ); }, removeAllReactions() { return removeAllReactions(this.channelID!, this.id!); @@ -111,11 +142,13 @@ export async function createMessage(data: MessageCreateOptions) { mentions: createNewProp(data.mentions.map((m) => m.id)), mentionsEveryone: createNewProp(mentionsEveryone), mentionRoleIDs: createNewProp(mentionRoleIDs), - mentionChannelIDs: createNewProp(mentionChannelIDs?.map(m => m.id) || []), + mentionChannelIDs: createNewProp(mentionChannelIDs?.map((m) => m.id) || []), webhookID: createNewProp(webhookID), messageReference: createNewProp(messageReference), timestamp: createNewProp(Date.parse(data.timestamp)), - editedTimestamp: createNewProp(editedTimestamp ? Date.parse(editedTimestamp) : undefined), + editedTimestamp: createNewProp( + editedTimestamp ? Date.parse(editedTimestamp) : undefined, + ), }); return message; @@ -172,7 +205,7 @@ export interface Message { stickers?: MessageSticker[]; /** The message id of the original message if this message was sent as a reply. If null, the original message was deleted. */ referencedMessageID?: MessageCreateOptions | null; - + // GETTERS /** The guild of this message. Can be undefined if not in cache or in DM */ @@ -207,13 +240,21 @@ export interface Message { /** Send a message to this channel where this message is */ reply(content: string | MessageContent): Promise; /** Send a message to this channel and then delete it after a bit. By default it will delete after 10 seconds with no reason provided. */ - alert(content: string | MessageContent, timeout?: number, reason?: string): Promise; + alert( + content: string | MessageContent, + timeout?: number, + reason?: string, + ): Promise; /** Send a inline reply to this message but then delete it after a bit. By default it will delete after 10 seconds with no reason provided. */ - alertResponse(content: string | MessageContent, timeout?: number, reason?: string): Promise; + alertResponse( + content: string | MessageContent, + timeout?: number, + reason?: string, + ): Promise; /** Remove all reactions */ removeAllReactions(): Promise; /** Remove all reactions */ removeReactionEmoji(reaction: string): Promise; /** Remove all reactions */ removeReaction(reaction: string): Promise; -} \ No newline at end of file +} diff --git a/src/structures/mod.ts b/src/structures/mod.ts index abbdea3b7..1a44569c4 100644 --- a/src/structures/mod.ts +++ b/src/structures/mod.ts @@ -17,9 +17,10 @@ export let structures = { export type Structures = typeof structures; -/** This function is used to update/reload/customize the internal structure of Discordeno. +/** This function is used to update/reload/customize the internal structures of Discordeno. * - * ⚠️ **ADVANCED USE ONLY: If you customize this in a wrong way, you could potentially create many new errors/bugs. Please take caution when using this. + * ⚠️ **ADVANCED USE ONLY: If you customize this incorrectly, you could potentially create many new errors/bugs. + * Please take caution when using this.** */ export function updateStructures(newStructures: Structures) { structures = { diff --git a/src/structures/template.ts b/src/structures/template.ts index bb199a20b..5aa6a2650 100644 --- a/src/structures/template.ts +++ b/src/structures/template.ts @@ -1,4 +1,13 @@ -import { GuildTemplate } from "../types/types.ts"; +import { GuildTemplate, UserPayload } from "../types/types.ts"; +import { cache } from "../utils/cache.ts"; +import { createNewProp } from "../utils/utils.ts"; +import { Guild } from "./guild.ts"; + +const baseTemplate: any = { + get sourceGuild() { + return cache.guilds.get(this.sourceGuildID); + }, +}; export function createTemplate( data: GuildTemplate, @@ -12,20 +21,52 @@ export function createTemplate( serialized_source_guild: serializedSourceGuild, is_dirty: isDirty, ...rest - } = data; + }: { [key: string]: any } = data; - const template = { - ...rest, - usageCount, - creatorID, - createdAt, - updatedAt, - sourceGuildID, - serializedSourceGuild, - isDirty, - }; + const restProps: Record> = {}; + for (const key of Object.keys(rest)) { + restProps[key] = createNewProp(rest[key]); + } + + const template = Object.create(baseTemplate, { + ...restProps, + usageCount: createNewProp(sourceGuildID), + creatorID: createNewProp(creatorID), + createdAt: createNewProp(createdAt), + updatedAt: createNewProp(updatedAt), + sourceGuildID: createNewProp(sourceGuildID), + serializedSourceGuild: createNewProp(serializedSourceGuild), + isDirty: createNewProp(isDirty), + }); return template; } -export interface Template extends ReturnType {} +export interface Template { + /** the template code (unique ID) */ + code: string; + /** template name */ + name: string; + /** the description for the template */ + description: string | null; + /** number of times this template has been used */ + usageCount: number; + /** the ID of the user who created the template */ + createdID: string; + /** the user who created the template */ + creator: UserPayload; + /** when this template was created */ + createdAt: string; + /** when this template was last synced to the source guild */ + updatedAt: string; + /** the ID of the guild this template is based on */ + sourceGuildID: string; + /** the guild snapshot this template contains */ + serializedSourceGuild: Partial; + /** whether the template has unsynced changes */ + isDirty: boolean | null; + + // GETTERS + + sourceGuild: Guild | undefined; +} diff --git a/src/types/misc.ts b/src/types/misc.ts deleted file mode 100644 index 84bb25051..000000000 --- a/src/types/misc.ts +++ /dev/null @@ -1,3 +0,0 @@ -export type Unpromise> = T extends Promise - ? K - : never; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 1c70309d8..7842637ff 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -34,6 +34,6 @@ 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) { +export function createNewProp(value: any): Partial { return { configurable: true, enumerable: true, writable: true, value }; } From 6ed345b87b6c84c070f75c7809a6331b2a6d00e3 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Sat, 19 Dec 2020 12:19:34 -0500 Subject: [PATCH 15/21] Update src/structures/role.ts Co-authored-by: Ayyan --- src/structures/role.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/role.ts b/src/structures/role.ts index 264cd7eb1..ad7113d94 100644 --- a/src/structures/role.ts +++ b/src/structures/role.ts @@ -23,7 +23,7 @@ const baseRole: Partial = { }, // METHODS - delete: function (guildID?: string) { + delete(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 From 707d4a667357df1da3308afcb0c76769daba0276 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Sat, 19 Dec 2020 12:19:57 -0500 Subject: [PATCH 16/21] Update src/structures/channel.ts Co-authored-by: Ayyan --- src/structures/channel.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/channel.ts b/src/structures/channel.ts index 545a341b7..0d6fba43d 100644 --- a/src/structures/channel.ts +++ b/src/structures/channel.ts @@ -36,7 +36,7 @@ export async function createChannel( ...rest } = data; - const restProps = {}; + const restProps: Record = {}; for (const key of Object.keys(rest)) { // @ts-ignore restProps[key] = createNewProp(rest[key]); From d7856f17d3500ea78cc8f899c9979f6835013cec Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Sat, 19 Dec 2020 12:20:10 -0500 Subject: [PATCH 17/21] Update src/structures/message.ts Co-authored-by: Ayyan --- src/structures/message.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/message.ts b/src/structures/message.ts index c502dc683..33736c9a7 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -127,7 +127,7 @@ export async function createMessage(data: MessageCreateOptions) { ...rest } = data; - const restProps = {}; + const restProps: Record = {}; for (const key of Object.keys(rest)) { // @ts-ignore restProps[key] = createNewProp(rest[key]); From e7ce52bab4b671c9d836897144b5103579cd5d6e Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Sat, 19 Dec 2020 12:20:19 -0500 Subject: [PATCH 18/21] Update src/structures/role.ts Co-authored-by: Ayyan --- src/structures/role.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/role.ts b/src/structures/role.ts index ad7113d94..ee76e0490 100644 --- a/src/structures/role.ts +++ b/src/structures/role.ts @@ -69,7 +69,7 @@ const baseRole: Partial = { export async function createRole(data: RoleData) { const { tags, ...rest } = data; - const restProps = {}; + const restProps: Record = {}; for (const key of Object.keys(rest)) { // @ts-ignore restProps[key] = createNewProp(rest[key]); From aa03e5ed4d9c7c44fda6637b24b84aaad390a24a Mon Sep 17 00:00:00 2001 From: ayntee Date: Sat, 19 Dec 2020 21:49:45 +0400 Subject: [PATCH 19/21] chore: remove @ts-ignore comments --- src/structures/channel.ts | 5 ++--- src/structures/member.ts | 6 ++---- src/structures/message.ts | 5 ++--- src/structures/role.ts | 5 ++--- src/structures/template.ts | 4 ++-- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/structures/channel.ts b/src/structures/channel.ts index 0d6fba43d..3a19b9c49 100644 --- a/src/structures/channel.ts +++ b/src/structures/channel.ts @@ -36,10 +36,9 @@ export async function createChannel( ...rest } = data; - const restProps: Record = {}; + const restProps: Record> = {}; for (const key of Object.keys(rest)) { - // @ts-ignore - restProps[key] = createNewProp(rest[key]); + restProps[key] = createNewProp((rest as any)[key]); } const channel = Object.create(baseChannel, { diff --git a/src/structures/member.ts b/src/structures/member.ts index c4dc53cbc..1b1a03b89 100644 --- a/src/structures/member.ts +++ b/src/structures/member.ts @@ -69,10 +69,9 @@ export async function createMember(data: MemberCreatePayload, guildID: string) { ...user } = data.user || {}; - const restProps = {}; + const restProps: Record> = {}; for (const key of Object.keys(rest)) { - // @ts-ignore - restProps[key] = createNewProp(rest[key]); + restProps[key] = createNewProp((rest as any)[key]); } for (const key of Object.keys(user)) { @@ -81,7 +80,6 @@ export async function createMember(data: MemberCreatePayload, guildID: string) { } const member = Object.create(baseMember, { - // INCASE DISCORD ADDS MORE DATA USERS OF OUR LIB GET IT INSTANTLY ...restProps, mfaEnabled: createNewProp(mfaEnabled), premiumType: createNewProp(premiumType), diff --git a/src/structures/message.ts b/src/structures/message.ts index 33736c9a7..e51b6af5f 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -127,10 +127,9 @@ export async function createMessage(data: MessageCreateOptions) { ...rest } = data; - const restProps: Record = {}; + const restProps: Record> = {}; for (const key of Object.keys(rest)) { - // @ts-ignore - restProps[key] = createNewProp(rest[key]); + restProps[key] = createNewProp((rest as any)[key]); } const message = Object.create(baseMessage, { diff --git a/src/structures/role.ts b/src/structures/role.ts index ee76e0490..7ca5fb656 100644 --- a/src/structures/role.ts +++ b/src/structures/role.ts @@ -69,10 +69,9 @@ const baseRole: Partial = { export async function createRole(data: RoleData) { const { tags, ...rest } = data; - const restProps: Record = {}; + const restProps: Record> = {}; for (const key of Object.keys(rest)) { - // @ts-ignore - restProps[key] = createNewProp(rest[key]); + restProps[key] = createNewProp((rest as any)[key]); } const role = Object.create(baseRole, { diff --git a/src/structures/template.ts b/src/structures/template.ts index 5aa6a2650..2863e598a 100644 --- a/src/structures/template.ts +++ b/src/structures/template.ts @@ -21,11 +21,11 @@ export function createTemplate( serialized_source_guild: serializedSourceGuild, is_dirty: isDirty, ...rest - }: { [key: string]: any } = data; + } = data; const restProps: Record> = {}; for (const key of Object.keys(rest)) { - restProps[key] = createNewProp(rest[key]); + restProps[key] = createNewProp((rest as any)[key]); } const template = Object.create(baseTemplate, { From 6e924f4ee6a1f5cf58f25e31b99008785e94ed6e Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Sat, 26 Dec 2020 22:41:28 +0000 Subject: [PATCH 20/21] add guild stuff --- src/api/structures/guild.ts | 253 ++++++++++++++++++++++++++++++++---- 1 file changed, 228 insertions(+), 25 deletions(-) diff --git a/src/api/structures/guild.ts b/src/api/structures/guild.ts index 8f8ae2374..6bcd79a49 100644 --- a/src/api/structures/guild.ts +++ b/src/api/structures/guild.ts @@ -1,13 +1,91 @@ -import { CreateGuildPayload, MemberCreatePayload } from "../../types/types.ts"; +import { botID } from "../../bot.ts"; +import { BannedUser, ChannelCreatePayload, CreateGuildPayload, Emoji, GetAuditLogsOptions, GuildEditOptions, GuildFeatures, GuildMember, ImageFormats, ImageSize, MemberCreatePayload, Presence, VoiceState } from "../../types/types.ts"; +import { cache } from "../../util/cache.ts"; import { Collection } from "../../util/collection.ts"; -import { structures } from "./mod.ts"; +import { deleteServer, editGuild, getAuditLogs, getBan, getBans, getInvites, guildBannerURL, guildIconURL, leaveGuild } from "../handlers/guild.ts"; +import { Member } from "./member.ts"; +import { Role, structures } from "./mod.ts"; +import { Channel } from "./structures.ts"; export const initialMemberLoadQueue = new Map(); -const baseGuild: any = {}; +const baseGuild: Partial = { + get members() { + return cache.members.filter(member => member.guilds.has(this.id!)); + }, + get channels() { + return cache.channels.filter(channel => channel.guildID === this.id); + }, + get afkChannel() { + return cache.channels.get(this.afkChannelID!); + }, + get publicUpdatesChannel() { + return cache.channels.get(this.publicUpdatesChannelID!); + }, + get rulesChannel() { + return cache.channels.get(this.rulesChannelID!); + }, + get systemChannel() { + return cache.channels.get(this.systemChannelID!); + }, + get bot() { + return cache.members.get(botID); + }, + get botMember() { + return this.bot?.guilds.get(this.id!); + }, + get botVoice() { + return this.voiceStates.get(botID); + }, + get owner() { + return cache.members.get(this.ownerID!); + }, + get partnered() { + return Boolean(this.features?.includes("PARTNERED")); + }, + get verified() { + return Boolean(this.features?.includes("VERIFIED")) + }, + bannerURL(size, format) { + return guildBannerURL(this as Guild, size, format); + }, + delete() { + return deleteServer(this.id!); + }, + edit(options) { + return editGuild(this.id!, options); + }, + auditLogs(options) { + return getAuditLogs(this.id!, options); + }, + getBan(memberID) { + return getBan(this.id!, memberID); + }, + bans() { + return getBans(this.id!); + }, + invites() { + return getInvites(this.id!); + }, + iconURL(size, format) { + return guildIconURL(this as Guild, size, format); + }, + leave() { + return leaveGuild(this.id!); + } +}; export async function createGuild(data: CreateGuildPayload, shardID: number) { const { + disovery_splash: discoverySplash, + default_message_notifications: defaultMessageNotifications, + explicit_content_filter: explicitContentFilter, + system_channel_flags: systemChannelFlags, + rules_channel_id: rulesChannelID, + public_updates_channel_id: publicUpdatesChannelID, + max_video_channel_users: maxVideoChannelUsers, + approximate_member_count: approximateMemberCount, +approximate_presence_count: approximatePresenceCount, owner_id: ownerID, afk_channel_id: afkChannelID, afk_timeout: afkTimeout, @@ -40,45 +118,33 @@ export async function createGuild(data: CreateGuildPayload, shardID: number) { const guild = { ...rest, - /** The shard id that this guild is on */ + discoverySplash, + defaultMessageNotifications, + explicitContentFilter, + rulesChannelID, + publicUpdatesChannelID, + maxVideoChannelUsers, + approximateMemberCount, +approximatePresenceCount, shardID, - /** The owner id of the guild. */ ownerID, - /** The afk channel id for this guild. */ afkChannelID, - /** The amount of time before a user is moved to AFK. */ afkTimeout, - /** Whether or not the embed is enabled in this server. */ widgetEnabled, - /** The channel id for the guild embed in this server. */ widgetChannelID, - /** The verification level for this server. */ verificationLevel, - /** The MFA level for this server. */ mfaLevel, - /** The system channel id for this server. */ systemChannelID, - /** The max presences for this server. */ maxPresences, - /** The maximum members in this server. */ maxMembers, - /** The vanity URL code for this server. */ vanityURLCode, - /** The premium tier for this server. */ premiumTier, - /** The subscription count for this server. */ premiumSubscriptionCount, - /** The preferred language in this server. */ preferredLocale, - /** The roles in the guild */ roles: new Collection(roles.map((r) => [r.id, r])), - /** When this guild was joined at. */ joinedAt: Date.parse(joinedAt), - /** The presences of all the users in the guild. */ presences: new Collection(data.presences.map((p) => [p.user.id, p])), - /** The total number of members in this guild. This value is updated as members leave and join the server. However, if you do not have the intent enabled to be able to listen to these events, then this will not be accurate. */ memberCount: memberCount || 0, - /** The Voice State data for each user in a voice channel in this server. */ voiceStates: new Collection(voiceStates.map((vs) => [vs.user_id, { ...vs, guildID: vs.guild_id, @@ -92,9 +158,146 @@ export async function createGuild(data: CreateGuildPayload, shardID: number) { }; initialMemberLoadQueue.set(guild.id, members); - // members.forEach((m) => structures.createMember(m, guild.id)); return guild; } -export interface Guild {} +export interface Guild { + /** The guild id */ + id: string; + /** The guild name 2-100 characters */ + name: string; + /** The guild icon image hash */ + icon: string | null; + /** The guild splash image hash */ + splash: string | null; + /** Discovery splash has; only present for guilds with the "DISCOVERABLE" feature */ + disoverySplash: string | null; + /** The voice region id for the guild */ + region: string; + /** Default message notifications level */ + defaultMessageNotifications: number; + /** Explicit content filter level */ + explicitContentFilter: number; + /** The custom guild emojis */ + emojis: Emoji[]; + /** Enabled guild features */ + features: GuildFeatures[]; + /** System channel flags */ + systemChannelFlags: number; + /** The id of the channel where guilds with the PUBLIC feature can display rules and or guidelines. */ + rulesChannelID: string | null; + /** The description for the guild */ + description: string | null; + /** The banner hash */ + banner: string | null; + /** The id of the channel where admins and moderators of guilds with the PUBLIC feature receive notices from Discord */ + publicUpdatesChannelID: string | null; + /** The maximum amount of users in a video channel. */ + maxVideoChannelUsers?: number; + /** The approximate number of members in this guild, returned from the GET /guild/id endpoint when with_counts is true */ + approximateMemberCount?: number; + /** The approximate number of non-offline members in this guild, returned from the GET /guild/id endpoint when with_counts is true */ + approximatePresenceCount?: number; + /** Whether this is considered a large guild */ + large: boolean; + /** Whether this guild is unavailable */ + unavailable: boolean; + /** The shard id that this guild is on */ + shardID: number, + /** The owner id of the guild. */ + ownerID: string; + /** The afk channel id for this guild. */ + afkChannelID: string; + /** The amount of time before a user is moved to AFK. */ + afkTimeout: number; + /** Whether or not the embed is enabled in this server. */ + widgetEnabled: boolean; + /** The channel id for the guild embed in this server. */ + widgetChannelID: string; + /** The verification level for this server. */ + verificationLevel: number; + /** The MFA level for this server. */ + mfaLevel: number; + /** The system channel id for this server. */ + systemChannelID: string; + /** The max presences for this server. */ + maxPresences: number; + /** The maximum members in this server. */ + maxMembers: number; + /** The vanity URL code for this server. */ + vanityURLCode: string; + /** The premium tier for this server. */ + premiumTier: number; + /** The subscription count for this server. */ + premiumSubscriptionCount: number; + /** The preferred language in this server. */ + preferredLocale: string; + /** The roles in the guild */ + roles: Collection; + /** When this guild was joined at. */ + joinedAt: number; + /** The presences of all the users in the guild. */ + presences: Collection, + /** The total number of members in this guild. This value is updated as members leave and join the server. However, if you do not have the intent enabled to be able to listen to these events, then this will not be accurate. */ + memberCount: number; + /** The Voice State data for each user in a voice channel in this server. */ + voiceStates: Collection, + + // GETTERS + /** Members in this guild. */ + members: Collection; + /** Channels in this guild. */ + channels: Collection; + /** The afk channel if one is set */ + afkChannel?: Channel; + /** The public update channel if one is set */ + publicUpdatesChannel?: Channel; + /** The rules channel in this guild if one is set */ + rulesChannel?: Channel; + /** The system channel in this guild if one is set */ + systemChannel?: Channel; + /** The bot member in this guild if cached */ + bot?: Member; + /** The bot guild member in this guild if cached */ + botMember?: GuildMember; + /** The bots voice state if there is one in this guild */ + botVoice?: CleanVoiceState; + /** The owner member of this guild */ + owner?: Member; + /** Whether or not this guild is partnered */ + partnered: boolean; + /** Whether or not this guild is verified */ + verified: boolean; + + // METHODS + + /** The banner url for this server */ + bannerURL(size?: ImageSize, format?: ImageFormats): string | undefined; + /** The full URL of the icon from Discords CDN. Undefined when no icon is set. */ + iconURL(size?: ImageSize, format?: ImageFormats): string | undefined; + /** Delete a guild permanently. User must be owner. Returns 204 No Content on success. Fires a Guild Delete Gateway event. */ + delete(): Promise; + /** Leave a guild */ + leave(): Promise; + /** Edit the server. Requires the MANAGE_GUILD permission. */ + edit(options: GuildEditOptions): Promise; + /** Returns the audit logs for the guild. Requires VIEW AUDIT LOGS permission */ + auditLogs(options: GetAuditLogsOptions): Promise; + /** Returns a ban object for the given user or a 404 not found if the ban cannot be found. Requires the BAN_MEMBERS permission. */ + getBan(memberID: string): Promise; + /** Returns a list of ban objects for the users banned from this guild. Requires the BAN_MEMBERS permission. */ + bans(): Promise>; + /** Get all the invites for this guild. Requires MANAGE_GUILD permission */ + invites(): Promise; +} + +interface CleanVoiceState extends VoiceState { + guildID: string; + channelID: string; + userID: string; + sessionID: string; + selfDeaf: boolean; + selfMute: boolean; + selfStream: boolean; +} From 4f12969cd8fd732cdeab9f7f97462882ea741d56 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Sat, 26 Dec 2020 23:35:58 +0000 Subject: [PATCH 21/21] fmt --- src/api/structures/guild.ts | 46 ++++++++++++++++++++++++++++--------- src/rest/request_manager.ts | 8 ++++++- src/util/constants.ts | 3 ++- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/api/structures/guild.ts b/src/api/structures/guild.ts index 6bcd79a49..60fa94a05 100644 --- a/src/api/structures/guild.ts +++ b/src/api/structures/guild.ts @@ -1,8 +1,32 @@ import { botID } from "../../bot.ts"; -import { BannedUser, ChannelCreatePayload, CreateGuildPayload, Emoji, GetAuditLogsOptions, GuildEditOptions, GuildFeatures, GuildMember, ImageFormats, ImageSize, MemberCreatePayload, Presence, VoiceState } from "../../types/types.ts"; +import { + BannedUser, + ChannelCreatePayload, + CreateGuildPayload, + Emoji, + GetAuditLogsOptions, + GuildEditOptions, + GuildFeatures, + GuildMember, + ImageFormats, + ImageSize, + MemberCreatePayload, + Presence, + VoiceState, +} from "../../types/types.ts"; import { cache } from "../../util/cache.ts"; import { Collection } from "../../util/collection.ts"; -import { deleteServer, editGuild, getAuditLogs, getBan, getBans, getInvites, guildBannerURL, guildIconURL, leaveGuild } from "../handlers/guild.ts"; +import { + deleteServer, + editGuild, + getAuditLogs, + getBan, + getBans, + getInvites, + guildBannerURL, + guildIconURL, + leaveGuild, +} from "../handlers/guild.ts"; import { Member } from "./member.ts"; import { Role, structures } from "./mod.ts"; import { Channel } from "./structures.ts"; @@ -11,10 +35,10 @@ export const initialMemberLoadQueue = new Map(); const baseGuild: Partial = { get members() { - return cache.members.filter(member => member.guilds.has(this.id!)); + return cache.members.filter((member) => member.guilds.has(this.id!)); }, get channels() { - return cache.channels.filter(channel => channel.guildID === this.id); + return cache.channels.filter((channel) => channel.guildID === this.id); }, get afkChannel() { return cache.channels.get(this.afkChannelID!); @@ -44,7 +68,7 @@ const baseGuild: Partial = { return Boolean(this.features?.includes("PARTNERED")); }, get verified() { - return Boolean(this.features?.includes("VERIFIED")) + return Boolean(this.features?.includes("VERIFIED")); }, bannerURL(size, format) { return guildBannerURL(this as Guild, size, format); @@ -72,7 +96,7 @@ const baseGuild: Partial = { }, leave() { return leaveGuild(this.id!); - } + }, }; export async function createGuild(data: CreateGuildPayload, shardID: number) { @@ -85,7 +109,7 @@ export async function createGuild(data: CreateGuildPayload, shardID: number) { public_updates_channel_id: publicUpdatesChannelID, max_video_channel_users: maxVideoChannelUsers, approximate_member_count: approximateMemberCount, -approximate_presence_count: approximatePresenceCount, + approximate_presence_count: approximatePresenceCount, owner_id: ownerID, afk_channel_id: afkChannelID, afk_timeout: afkTimeout, @@ -125,7 +149,7 @@ approximate_presence_count: approximatePresenceCount, publicUpdatesChannelID, maxVideoChannelUsers, approximateMemberCount, -approximatePresenceCount, + approximatePresenceCount, shardID, ownerID, afkChannelID, @@ -204,7 +228,7 @@ export interface Guild { /** Whether this guild is unavailable */ unavailable: boolean; /** The shard id that this guild is on */ - shardID: number, + shardID: number; /** The owner id of the guild. */ ownerID: string; /** The afk channel id for this guild. */ @@ -238,11 +262,11 @@ export interface Guild { /** When this guild was joined at. */ joinedAt: number; /** The presences of all the users in the guild. */ - presences: Collection, + presences: Collection; /** The total number of members in this guild. This value is updated as members leave and join the server. However, if you do not have the intent enabled to be able to listen to these events, then this will not be accurate. */ memberCount: number; /** The Voice State data for each user in a voice channel in this server. */ - voiceStates: Collection, + voiceStates: Collection; // GETTERS /** Members in this guild. */ diff --git a/src/rest/request_manager.ts b/src/rest/request_manager.ts index 64880892c..e1be393fb 100644 --- a/src/rest/request_manager.ts +++ b/src/rest/request_manager.ts @@ -1,6 +1,12 @@ import { authorization, eventHandlers } from "../bot.ts"; import { Errors, HttpResponseCode, RequestMethods } from "../types/types.ts"; -import { API_VERSION, baseEndpoints, BASE_URL, IMAGE_BASE_URL, USER_AGENT } from "../util/constants.ts"; +import { + API_VERSION, + BASE_URL, + baseEndpoints, + IMAGE_BASE_URL, + USER_AGENT, +} from "../util/constants.ts"; import { delay } from "../util/utils.ts"; const pathQueues: { [key: string]: QueuedRequest[] } = {}; diff --git a/src/util/constants.ts b/src/util/constants.ts index 251e97a46..6064a75b2 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -5,7 +5,8 @@ export const BASE_URL = "https://discord.com/api"; export const API_VERSION = 8; /** https://discord.com/developers/docs/reference#user-agent */ -export const USER_AGENT = "DiscordBot (https://github.com/discordeno/discordeno, v10)"; +export const USER_AGENT = + "DiscordBot (https://github.com/discordeno/discordeno, v10)"; /** https://discord.com/developers/docs/reference#image-formatting-image-base-url */ export const IMAGE_BASE_URL = "https://cdn.discordapp.com/";