Skip to content
This repository has been archived by the owner on Mar 25, 2020. It is now read-only.

Fixed lots issues with the typescript typings file and added additional typings #325

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.vs
node_modules
package-lock.json
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
139 changes: 107 additions & 32 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,81 @@
*/
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;

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: {
unavailable: boolean;
id: string;
}[];
application: {
id: string;
flags: number;
};
_trace: string[];
};

declare type WebSocketEventMessage = {
type: number;
tts: boolean;
timestamp: string;
pinned: boolean;
nonce: string;
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: embedMessageOpts[];
edited_timestamp?: any;
content: string;
channel_id: string;
author: Discord.User;
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<EventType=any> = {
d: EventType;
op: number;
s: number;
t: string;
Expand All @@ -18,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";
Expand All @@ -28,9 +100,9 @@ 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 presenceCallback = (user: string, userID: string, status: string, game: game, event: WebSocketEvent) => void;
declare type readyCallback = (event: WebSocketEvent<WebSocketEventReady>) => void;
declare type messageCallback = (user: string, userID: string, channelID: string, message: string, event: WebSocketEvent<WebSocketEventMessage>) => void;
declare type presenceCallback = (user: string, userID: string, status: string, game: game, event: WebSocketEvent<WebSocketEventPresence>) => void;
declare type anyCallback = (event: WebSocketEvent) => void;
declare type disconnectCallback = (errMsg: string, code: number) => void;

Expand Down Expand Up @@ -128,18 +200,19 @@ declare type sendMessageOpts = {
}

declare type embedMessageOpts = {
type?: string;
author?: {
icon_url?: string,
name: string,
url?: string
},
color?: number,
description?: string,
fields?: [{
fields?: {
name: string,
value?: string,
inline?: boolean
}],
}[],
thumbnail?: {
url: string
},
Expand Down Expand Up @@ -232,7 +305,7 @@ declare type setPresenceOpts = {
declare type addAndRemoveFromRole = {
serverID: string,
userID: string,
role: string
roleID: string
}

declare type moveUserToOpts = {
Expand All @@ -242,13 +315,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
}

Expand Down Expand Up @@ -288,7 +361,7 @@ declare type editRoleOpts = {

declare type deleteRoleOpts = {
serverID: string,
role: string
roleID: string
}

declare type editNicknameOpts = {
Expand All @@ -313,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 = {
Expand Down Expand Up @@ -411,12 +484,14 @@ declare namespace Discord {
}

export class User extends Resource {
username: string;
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 {
Expand Down Expand Up @@ -445,7 +520,7 @@ declare namespace Discord {
id: string;
username: string;
email: string;
discriminator: number;
discriminator: string;
avatar: string;
bot: boolean;
verified: boolean;
Expand Down