From cc506b25a0a75bc024ce1dd57257ee8cfe0c9901 Mon Sep 17 00:00:00 2001 From: josua Date: Tue, 10 Mar 2020 10:27:30 +1100 Subject: [PATCH 1/6] Fixed some spelling mistakes in the typescript typings, like mesage instead of message and role instead of roleID --- typings/index.d.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 5ba4a278..991cd52e 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -29,7 +29,7 @@ declare type channelType = "voice" | "text"; * Events callbacks */ declare type readyCallback = (event: WebSocketEvent) => void; -declare type messageCallback = (user: string, userID: string, channelID: string, mesage: string, event: WebSocketEvent) => void; +declare type messageCallback = (user: string, userID: string, channelID: string, message: string, event: WebSocketEvent) => void; declare type presenceCallback = (user: string, userID: string, status: string, game: game, event: WebSocketEvent) => void; declare type anyCallback = (event: WebSocketEvent) => void; declare type disconnectCallback = (errMsg: string, code: number) => void; @@ -232,7 +232,7 @@ declare type setPresenceOpts = { declare type addAndRemoveFromRole = { serverID: string, userID: string, - role: string + roleID: string } declare type moveUserToOpts = { @@ -242,13 +242,13 @@ declare type moveUserToOpts = { } declare type actionsOnUserOpts = { - channelID: string, - target: string + serverID: string, + userID: string, } declare type banUserOpts = { - channelID: string, - target: string, + serverID: string, + userID: string, lastDays?: number } @@ -288,7 +288,7 @@ declare type editRoleOpts = { declare type deleteRoleOpts = { serverID: string, - role: string + roleID: string } declare type editNicknameOpts = { @@ -300,7 +300,7 @@ declare type editNicknameOpts = { declare type editChannelPermissionsOpts = { channelID: string, userID: string, - roleID: string, + role: string, allow: Discord.Permissions[], deny: Discord.Permissions[], default: Discord.Permissions[] From 4c6b4fb7e2f81292b82ddde3d251914a86f4fef5 Mon Sep 17 00:00:00 2001 From: josua Date: Tue, 10 Mar 2020 10:35:57 +1100 Subject: [PATCH 2/6] Fixed the fields parameter in embedMessageOpts in the typescript typings --- typings/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 991cd52e..7b68070d 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -135,11 +135,11 @@ declare type embedMessageOpts = { }, color?: number, description?: string, - fields?: [{ + fields?: { name: string, value?: string, inline?: boolean - }], + }[], thumbnail?: { url: string }, From f4fdb3f57ce3b9139a8218f88aad3baf8bca2473 Mon Sep 17 00:00:00 2001 From: josua Date: Tue, 10 Mar 2020 11:08:25 +1100 Subject: [PATCH 3/6] Add better typings for WebSocketEvent for message and ready. --- typings/index.d.ts | 58 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 7b68070d..704671cd 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -7,8 +7,45 @@ declare type userStatus = "online" | "idle" | "offline"; declare type callbackFunc = (error: cbError, response: any) => void; -declare type WebSocketEvent = { - d: any; +declare type WebSocketEventReady = { + v: number; + user_settings: any; + user: Discord.User, + session_id: string; + relationships: any[]; + private_channels: any[]; + presences: any[]; + guilds: any[]; + application: { + id: string; + flags: number; + }; + _trace: string[]; +}; + +declare type WebSocketEventMessage = { + type: number; + tts: boolean; + timestamp: string; + pinned: boolean; + nonce: string; + mentions: any[]; + mention_roles: any[]; + mention_everyone: boolean; + member: Discord.Member; + id: string; + flags: number; + embeds: any[]; + edited_timestamp?: any; + content: string; + channel_id: string; + author: Discord.User; + attachments: any[]; + guild_id: string; +}; + +declare type WebSocketEvent = { + d: EventType; op: number; s: number; t: string; @@ -28,8 +65,8 @@ declare type channelType = "voice" | "text"; /** * Events callbacks */ -declare type readyCallback = (event: WebSocketEvent) => void; -declare type messageCallback = (user: string, userID: string, channelID: string, message: string, event: WebSocketEvent) => void; +declare type readyCallback = (event: WebSocketEvent) => void; +declare type messageCallback = (user: string, userID: string, channelID: string, message: string, event: WebSocketEvent) => void; declare type presenceCallback = (user: string, userID: string, status: string, game: game, event: WebSocketEvent) => void; declare type anyCallback = (event: WebSocketEvent) => void; declare type disconnectCallback = (errMsg: string, code: number) => void; @@ -413,14 +450,17 @@ declare namespace Discord { export class User extends Resource { username: string; id: string; - discriminator: number; - avatar: string; - bot: boolean; - game: Object; + discriminator: string; + avatar?: string; + verified?: boolean; + mfa_enabled?: boolean; + email?: any; + bot?: boolean; } export class Member extends Resource { id: string; + discriminator: string; roles: string[]; mute: boolean; joined_at: string; @@ -445,7 +485,7 @@ declare namespace Discord { id: string; username: string; email: string; - discriminator: number; + discriminator: string; avatar: string; bot: boolean; verified: boolean; From aa238035177a05e614c44e48747d342e6696f38e Mon Sep 17 00:00:00 2001 From: josua Date: Tue, 10 Mar 2020 12:18:34 +1100 Subject: [PATCH 4/6] Removed some "any" types from the typescript types file. Added types for the presence event. --- typings/index.d.ts | 55 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 704671cd..d2b4b6d6 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -3,7 +3,7 @@ */ declare type region = "brazil" | "frankfurt" | "amsterdam" | "london" | "singapore" | "us-east" | "us-central" | "us-south" | "us-west" | "sydney"; -declare type userStatus = "online" | "idle" | "offline"; +declare type userStatus = "online" | "idle" | "dnd" | "offline"; declare type callbackFunc = (error: cbError, response: any) => void; @@ -15,7 +15,10 @@ declare type WebSocketEventReady = { relationships: any[]; private_channels: any[]; presences: any[]; - guilds: any[]; + guilds: { + unavailable: boolean; + id: string; + }[]; application: { id: string; flags: number; @@ -29,21 +32,50 @@ declare type WebSocketEventMessage = { timestamp: string; pinned: boolean; nonce: string; - mentions: any[]; - mention_roles: any[]; + mentions: { + username: string; + member: Discord.Member; + id: string; + discriminator: string; + bot?: boolean; + avatar?: string; + }[]; + mention_roles: string[]; mention_everyone: boolean; member: Discord.Member; id: string; flags: number; - embeds: any[]; + embeds: embedMessageOpts[]; edited_timestamp?: any; content: string; channel_id: string; author: Discord.User; - attachments: any[]; + attachments: { + width: number; + height: number; + size: number; + id: string; + filename: string; + url: string; + proxy_url: string; + }[]; guild_id: string; }; +declare type WebSocketEventPresence = { + user: Discord.User; + status: userStatus; + roles: string[]; + guild_id: string; + game?: game; + client_status: { + web?: userStatus; + desktop?: userStatus; + mobile?: userStatus; + }; + activities: game[]; +}; + declare type WebSocketEvent = { d: EventType; op: number; @@ -55,6 +87,9 @@ declare type game = { name: string; type: number; url?: string; + created_at?: number; + id?: string; + state?: string; }; declare type colors = "DEFAULT" | "AQUA" | "GREEN" | "BLUE" | "PURPLE" | "GOLD" | "ORANGE" | "RED" | "GREY" | "DARKER_GREY" | "NAVY" | "DARK_AQUA" | "DARK_GREEN" | "DARK_BLUE" | "DARK_PURPLE" | "DARK_GOLD" | "DARK_ORANGE" | "DARK_RED" | "DARK_GREY" | "LIGHT_GREY" | "DARK_NAVY"; @@ -67,7 +102,7 @@ declare type channelType = "voice" | "text"; */ declare type readyCallback = (event: WebSocketEvent) => void; declare type messageCallback = (user: string, userID: string, channelID: string, message: string, event: WebSocketEvent) => void; -declare type presenceCallback = (user: string, userID: string, status: string, game: game, event: WebSocketEvent) => void; +declare type presenceCallback = (user: string, userID: string, status: string, game: game, event: WebSocketEvent) => void; declare type anyCallback = (event: WebSocketEvent) => void; declare type disconnectCallback = (errMsg: string, code: number) => void; @@ -165,6 +200,7 @@ declare type sendMessageOpts = { } declare type embedMessageOpts = { + type?: string; author?: { icon_url?: string, name: string, @@ -448,9 +484,9 @@ declare namespace Discord { } export class User extends Resource { - username: string; + username?: string; id: string; - discriminator: string; + discriminator?: string; avatar?: string; verified?: boolean; mfa_enabled?: boolean; @@ -460,7 +496,6 @@ declare namespace Discord { export class Member extends Resource { id: string; - discriminator: string; roles: string[]; mute: boolean; joined_at: string; From 1a7abb9ffd51880b88000e2c281f381e85380342 Mon Sep 17 00:00:00 2001 From: josua Date: Tue, 10 Mar 2020 12:33:15 +1100 Subject: [PATCH 5/6] Changed "role" to "roleID" in *Opts declarations in the type definitions file --- typings/index.d.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index d2b4b6d6..db1177ef 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -373,7 +373,7 @@ declare type editNicknameOpts = { declare type editChannelPermissionsOpts = { channelID: string, userID: string, - role: string, + roleID: string, allow: Discord.Permissions[], deny: Discord.Permissions[], default: Discord.Permissions[] @@ -386,27 +386,27 @@ declare type editServerWidgetOpts = { } declare type addServerEmojiOpts = { - serverID: string, - name: string, - image: string + serverID: string, + name: string, + image: string } declare type editServerEmojiOpts = { - serverID: string, - emojiID: string, - name: string, - role: string[] + serverID: string, + emojiID: string, + name: string, + roleID: string[] } declare type deleteServerEmojiOpts = { - serverID: string, - emojiID: string + serverID: string, + emojiID: string } declare type deleteChannelPermissionOpts = { - channelID: string, - userID: string, - roleID: string + channelID: string, + userID: string, + roleID: string } declare type editNoteOpts = { From 6fb2ab1b705bf6d7417bb6a44f7d87adb87ebb63 Mon Sep 17 00:00:00 2001 From: josua Date: Tue, 10 Mar 2020 15:17:40 +1100 Subject: [PATCH 6/6] Added files/folders to .gitignore, updated README --- .gitignore | 2 ++ README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 360ea127..3af3a3cd 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ .vs +node_modules +package-lock.json \ No newline at end of file diff --git a/README.md b/README.md index c76d8f14..ba9e9487 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ A small, single-file, fully featured [Discordapp](https://discordapp.com) librar **[Stable](https://www.npmjs.com/package/discord.io)** `npm install discord.io` -**[Latest](https://github.com/izy521/discord.io)** -`npm install izy521/discord.io` +**[Latest](https://github.com/jsrobson10/discord.io)** +`npm install jsrobson10/discord.io` #### Example ```javascript