From f70a989a21dc03dfa9d1d6494c9df4f6a7b9e1fc Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 23 Jan 2021 20:15:11 +0100 Subject: [PATCH 1/6] types: better types (#413) * Update cache.ts * Update shard_manager.ts --- src/util/cache.ts | 11 ++++++++--- src/ws/shard_manager.ts | 8 +++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/util/cache.ts b/src/util/cache.ts index c3be7a26c..61fa1a7ba 100644 --- a/src/util/cache.ts +++ b/src/util/cache.ts @@ -10,9 +10,14 @@ export interface CacheData { members: Collection; unavailableGuilds: Collection; presences: Collection; - // TODO: The type Collection's second provided generic [function] should have a definite shape. - // deno-lint-ignore ban-types - fetchAllMembersProcessingRequests: Collection; + fetchAllMembersProcessingRequests: Collection< + string, + ( + value: + | Collection + | PromiseLike>, + ) => void + >; executedSlashCommands: Collection; } diff --git a/src/ws/shard_manager.ts b/src/ws/shard_manager.ts index 4692632f4..4d92625fa 100644 --- a/src/ws/shard_manager.ts +++ b/src/ws/shard_manager.ts @@ -1,5 +1,6 @@ import { controllers } from "../api/controllers/mod.ts"; import { Guild } from "../api/structures/guild.ts"; +import { Member } from "../api/structures/mod.ts"; import { eventHandlers, IdentifyPayload } from "../bot.ts"; import { DiscordBotGatewayData, @@ -8,6 +9,7 @@ import { GatewayOpcode, } from "../types/mod.ts"; import { cache } from "../util/cache.ts"; +import { Collection } from "../util/collection.ts"; import { BotStatusRequest, delay } from "../util/utils.ts"; import { botGatewayStatusRequest, @@ -90,9 +92,9 @@ export async function handleDiscordPayload( export function requestAllMembers( guild: Guild, - // TODO: The parameter "resolve" should have a "stronger" type. - // deno-lint-ignore ban-types - resolve: Function, + resolve: ( + value: Collection | PromiseLike>, + ) => void, options?: FetchMembersOptions, ) { const nonce = `${guild.id}-${Date.now()}`; From 26f8321ee9d359eb3328f0e00b7a039b0c69ad5f Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 23 Jan 2021 20:16:04 +0100 Subject: [PATCH 2/6] feat(ws): add additional info to wsError debug event (#434) * feat(ws): better error debug message * Update src/ws/shard.ts Co-authored-by: Ayyan Co-authored-by: Ayyan --- src/ws/shard.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ws/shard.ts b/src/ws/shard.ts index 748c4f941..1acd29a3f 100644 --- a/src/ws/shard.ts +++ b/src/ws/shard.ts @@ -67,8 +67,11 @@ export function createShard( } }; - ws.onerror = ({ timeStamp }) => { - eventHandlers.debug?.({ type: "wsError", data: { timeStamp } }); + ws.onerror = (errorEvent) => { + eventHandlers.debug?.({ + type: "wsError", + data: { shardID: basicShard.id, ...errorEvent }, + }); }; ws.onmessage = ({ data: message }) => { From f6f435bb1f0ed89640c4f5d105c1d9fc249bb30f Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 23 Jan 2021 20:17:11 +0100 Subject: [PATCH 3/6] feat(handlers): add getAvailableVoiceRegions() (#425) * add voice endpoint * feat(handlers): add getVoiceRegions * Update mod.ts * remove breaking changes --- src/api/handlers/guild.ts | 5 +++++ src/api/handlers/mod.ts | 2 ++ src/util/constants.ts | 3 +++ 3 files changed, 10 insertions(+) diff --git a/src/api/handlers/guild.ts b/src/api/handlers/guild.ts index b70e532ab..f290d4dc1 100644 --- a/src/api/handlers/guild.ts +++ b/src/api/handlers/guild.ts @@ -729,6 +729,11 @@ export function leaveGuild(guildID: string) { return RequestManager.delete(endpoints.GUILD_LEAVE(guildID)); } +/** Returns an array of voice regions that can be used when creating servers. */ +export function getAvailableVoiceRegions() { + return RequestManager.get(endpoints.VOICE_REGIONS); +} + /** Returns a list of voice region objects for the guild. Unlike the similar /voice route, this returns VIP servers when the guild is VIP-enabled. */ export function getVoiceRegions(guildID: string) { return RequestManager.get(endpoints.GUILD_REGIONS(guildID)); diff --git a/src/api/handlers/mod.ts b/src/api/handlers/mod.ts index c76b4227c..9d10d70f9 100644 --- a/src/api/handlers/mod.ts +++ b/src/api/handlers/mod.ts @@ -40,6 +40,7 @@ import { emojiURL, fetchMembers, getAuditLogs, + getAvailableVoiceRegions, getBan, getBans, getChannel, @@ -171,6 +172,7 @@ export let handlers = { getGuildPreview, getGuildTemplate, getGuildTemplates, + getAvailableVoiceRegions, getIntegrations, getInvites, getMember, diff --git a/src/util/constants.ts b/src/util/constants.ts index bde99b4a8..03674cb29 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -117,6 +117,9 @@ export const endpoints = { GUILD_TEMPLATES: (guildID: string) => `${GUILDS_BASE(guildID)}/templates`, GUILD_PREVIEW: (guildID: string) => `${GUILDS_BASE(guildID)}/preview`, + // Voice + VOICE_REGIONS: `${baseEndpoints.BASE_URL}/voice/regions`, + INVITE: (inviteCode: string) => `${baseEndpoints.BASE_URL}/invites/${inviteCode}`, From 55235e5ea06b0a5796ee963e7d957c564cc1e17f Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sat, 23 Jan 2021 20:17:50 +0100 Subject: [PATCH 4/6] feat(handlers): add getTemplate() (#422) * feat(handlers): getTemplate * update jsdoc * redirect this function * remove getGuildTemplate * Update src/api/handlers/guild.ts Co-authored-by: Ayyan * remove breaking change * save in const * Update src/api/handlers/guild.ts Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> * Update src/api/handlers/guild.ts * Update src/api/handlers/guild.ts * Update mod.ts Co-authored-by: Ayyan Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> --- src/api/handlers/guild.ts | 16 +++++++++++++--- src/api/handlers/mod.ts | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/api/handlers/guild.ts b/src/api/handlers/guild.ts index f290d4dc1..c57d6c810 100644 --- a/src/api/handlers/guild.ts +++ b/src/api/handlers/guild.ts @@ -772,13 +772,23 @@ export function getGuild(guildID: string, counts = true) { } /** Returns the guild template if it exists */ +export async function getTemplate(templateCode: string) { + const result = await RequestManager.get( + endpoints.GUILD_TEMPLATE(templateCode), + ) as GuildTemplate; + const template = await structures.createTemplate(result); + return template; +} + +/** + * Returns the guild template if it exists + * @deprecated will get removed in v11 use `getTemplate` instead + */ export function getGuildTemplate( guildID: string, templateCode: string, ) { - return RequestManager.get( - `${endpoints.GUILD_TEMPLATES(guildID)}/${templateCode}`, - ) as Promise