Skip to content

Commit

Permalink
Fix types, docs, lint (#1190)
Browse files Browse the repository at this point in the history
Co-authored-by: abal <github@abal.moe>
  • Loading branch information
bsian03 and abalabahaha authored Apr 29, 2021
1 parent 939b70f commit 340ffe9
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 64 deletions.
101 changes: 81 additions & 20 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { Duplex, Readable as ReadableStream, Stream } from "stream";
import { Agent as HTTPSAgent } from "https";
import { IncomingMessage, ClientRequest } from "http";
import OpusScript = require("opusscript"); // Thanks TypeScript
import { URL } from "url";
import { Socket as DgramSocket } from "dgram";
import * as WebSocket from "ws";

declare function Eris(token: string, options?: Eris.ClientOptions): Eris.Client;

Expand Down Expand Up @@ -561,7 +564,6 @@ declare namespace Eris {
interface LatencyRef {
lastTimeOffsetCheck: number;
latency: number;
offset: number;
raw: number[];
timeOffset: number;
timeOffsets: number[];
Expand All @@ -582,6 +584,12 @@ declare namespace Eris {
short: boolean;
url: string;
}
interface RequestMembersPromise {
members: Member;
received: number;
res: (value: Member[]) => void;
timeout: NodeJS.Timeout;
}

// Guild
interface CreateGuildOptions {
Expand Down Expand Up @@ -798,6 +806,13 @@ declare namespace Eris {
file: Buffer | string;
name: string;
}
interface MessageInteraction {
id: string;
member: Member | null;
name: string;
type: InteractionType;
user: User;
}
interface MessageReference extends MessageReferenceBase {
channelID: string;
}
Expand All @@ -819,13 +834,6 @@ declare namespace Eris {
pack_id: string;
tags?: string;
}
interface MessageInteraction {
id: string;
type: InteractionType;
name: string;
user: User;
member: Member | null;
}

// Presence
interface Activity extends ActivityPartial<ActivityType> {
Expand Down Expand Up @@ -892,7 +900,7 @@ declare namespace Eris {
interface RoleTags {
bot_id?: string;
integration_id?: string;
premium_subscriber?: boolean;
premium_subscriber?: true;
}

// Voice
Expand All @@ -910,7 +918,8 @@ declare namespace Eris {
frameSize?: number;
inlineVolume?: boolean;
inputArgs?: string[];
sampleRate?: number;
pcmSize?: number;
samplingRate?: number;
voiceDataTimeout?: number;
}
interface VoiceServerUpdateData extends Omit<VoiceConnectData, "channel_id"> {
Expand All @@ -923,11 +932,14 @@ declare namespace Eris {
suppress?: boolean;
}
interface VoiceStreamCurrent {
buffer: Buffer | null;
bufferingTicks: number;
options: VoiceResourceOptions;
pausedTime?: number;
pausedTimestamp?: number;
playTime: number;
startTime: number;
timeout: NodeJS.Timeout | null;
}

// Webhook
Expand Down Expand Up @@ -1298,6 +1310,7 @@ declare namespace Eris {
createdAt: number;
id: string;
constructor(id: string);
static getCreatedAt(id: string): number;
inspect(): this;
toString(): string;
toJSON(props?: string[]): JSONCache;
Expand Down Expand Up @@ -1566,7 +1579,7 @@ declare namespace Eris {
editGuildIntegration(guildID: string, integrationID: string, options: IntegrationOptions): Promise<void>;
editGuildMember(guildID: string, memberID: string, options: MemberOptions, reason?: string): Promise<void>;
editGuildTemplate(guildID: string, code: string, options: GuildTemplateOptions): Promise<GuildTemplate>;
editGuildVanity(guildID: string, code: string): Promise<GuildVanity>;
editGuildVanity(guildID: string, code: string | null): Promise<GuildVanity>;
editGuildVoiceState(guildID: string, options: VoiceStateOptions, userID?: string): Promise<void>;
editGuildWelcomeScreen(guildID: string, options: WelcomeScreenOptions): Promise<WelcomeScreen>;
editGuildWidget(guildID: string, options: Widget): Promise<Widget>;
Expand Down Expand Up @@ -1902,7 +1915,6 @@ declare namespace Eris {
welcomeScreen?: WelcomeScreen;
widgetChannelID?: string | null;
widgetEnabled?: boolean | null;

constructor(data: BaseData, client: Client);
addDiscoverySubcategory(categoryID: string, reason?: string): Promise<DiscoverySubcategoryResponse>;
addMemberRole(memberID: string, roleID: string, reason?: string): Promise<void>;
Expand Down Expand Up @@ -1950,11 +1962,10 @@ declare namespace Eris {
editNickname(nick: string): Promise<void>;
editRole(roleID: string, options: RoleOptions): Promise<Role>;
editTemplate(code: string, options: GuildTemplateOptions): Promise<GuildTemplate>;
editVanity(code: string): Promise<GuildVanity>;
editVanity(code: string | null): Promise<GuildVanity>;
editVoiceState(options: VoiceStateOptions, userID?: string): Promise<void>;
editWelcomeScreen(options: WelcomeScreenOptions): Promise<WelcomeScreen>;
editWidget(options: Widget): Promise<Widget>;

fetchAllMembers(timeout?: number): Promise<number>;
fetchMembers(options?: FetchMembersOptions): Promise<Member[]>;
getAuditLogs(limit?: number, before?: string, actionType?: number, userID?: string): Promise<GuildAuditLog>;
Expand Down Expand Up @@ -2075,7 +2086,6 @@ declare namespace Eris {
dynamicDiscoverySplashURL(format?: ImageFormat, size?: number): string;
dynamicIconURL(format?: ImageFormat, size?: number): string;
dynamicSplashURL(format?: ImageFormat, size?: number): string;

}

export class GuildTemplate {
Expand Down Expand Up @@ -2186,7 +2196,6 @@ declare namespace Eris {
referencedMessage?: Message | null;
roleMentions: string[];
stickers?: Sticker[];

timestamp: number;
tts: boolean;
type: number;
Expand Down Expand Up @@ -2356,15 +2365,34 @@ declare namespace Eris {

export class Shard extends EventEmitter implements SimpleJSON {
client: Client;
connectAttempts: number;
connecting: boolean;
connectTimeout: NodeJS.Timeout | null;
discordServerTrace?: string[];
getAllUsersCount: { [guildID: string]: boolean };
getAllUsersLength: number;
getAllUsersQueue: string;
globalBucket: Bucket;
guildCreateTimeout: NodeJS.Timeout | null;
guildSyncQueue: string[];
guildSyncQueueLength: number;
heartbeatInterval: NodeJS.Timeout | null;
id: number;
lastHeartbeatReceived: number;
lastHeartbeatSent: number;
lastHeartbeatAck: boolean;
lastHeartbeatReceived: number | null;
lastHeartbeatSent: number | null;
latency: number;
preReady: boolean;
presence: Presence;
presenceUpdateBucket: Bucket;
ready: boolean;
reconnectInterval: number;
requestMembersPromise: { [s: string]: RequestMembersPromise };
seq: number;
sessionID: string | null;
status: "disconnected" | "connecting" | "handshaking" | "ready" | "resuming";
unsyncedGuilds: number;
ws: WebSocket | BrowserWebSocket | null;
constructor(id: number, client: Client);
checkReady(): void;
connect(): void;
Expand Down Expand Up @@ -2524,14 +2552,47 @@ declare namespace Eris {
}

export class VoiceConnection extends EventEmitter implements SimpleJSON {
channelID: string;
bitrate: number;
channelID: string | null;
channels: number;
connecting: boolean;
current?: VoiceStreamCurrent;
connectionTimeout: NodeJS.Timeout | null;
current?: VoiceStreamCurrent | null;
ended?: boolean;
endpoint: URL;
frameDuration: number;
frameSize: number;
heartbeatInterval: NodeJS.Timeout | null;
id: string;
mode?: string;
modes?: string;
/** Optional dependencies OpusScript (opusscript) or OpusEncoder (@discordjs/opus) */
opus: { [userID: string]: unknown };
opusOnly: boolean;
paused: boolean;
pcmSize: number;
piper: Piper;
playing: boolean;
ready: boolean;
receiveStreamOpus?: VoiceDataStream | null;
receiveStreamPCM?: VoiceDataStream | null;
reconnecting: boolean;
samplingRate: number;
secret: Buffer;
sendBuffer: Buffer;
sendNonce: Buffer;
sequence: number;
shard: Shard | Record<string, never>;
shared: boolean;
speaking: boolean;
ssrc?: number;
ssrcUserMap: { [s: number]: string };
timestamp: number;
udpIP?: string;
udpPort?: number;
udpSocket: DgramSocket | null;
volume: number;
ws: BrowserWebSocket | WebSocket | null;
constructor(id: string, options?: { shard?: Shard; shared?: boolean; opusOnly?: boolean });
connect(data: VoiceConnectData): NodeJS.Timer | void;
disconnect(error?: Error, reconnecting?: boolean): void;
Expand Down
4 changes: 2 additions & 2 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ class Client extends EventEmitter {
/**
* Modify a guild's vanity code
* @arg {String} guildID The ID of the guild
* @arg {String} code The new vanity code
* @arg {String?} code The new vanity code
* @returns {Promise<Object>}
*/
editGuildVanity(guildID, code) {
Expand Down Expand Up @@ -2159,7 +2159,7 @@ class Client extends EventEmitter {
* @returns {Promise<Message>} Resolves with a webhook message
*/
getWebhookMessage(webhookID, token, messageID) {
return this.requestHandler.request("GET", Endpoints.WEBHOOK_MESSAGE(webhookID, token, messageID), true).then((message) => new Message(message, this));
return this.requestHandler.request("GET", Endpoints.WEBHOOK_MESSAGE(webhookID, token, messageID)).then((message) => new Message(message, this));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/gateway/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class Shard extends EventEmitter {
}
this.lastHeartbeatAck = false;
}
this.lastHeartbeatSent = new Date().getTime();
this.lastHeartbeatSent = Date.now();
this.sendWS(GatewayOPCodes.HEARTBEAT, this.seq, true);
}

Expand Down Expand Up @@ -451,7 +451,7 @@ class Shard extends EventEmitter {
}
case GatewayOPCodes.HEARTBEAT_ACK: {
this.lastHeartbeatAck = true;
this.lastHeartbeatReceived = new Date().getTime();
this.lastHeartbeatReceived = Date.now();
this.latency = this.lastHeartbeatReceived - this.lastHeartbeatSent;
break;
}
Expand Down Expand Up @@ -1257,7 +1257,7 @@ class Shard extends EventEmitter {
* @prop {Number} oldGuild.maxPresences The maximum number of people that can be online in a guild at once (returned from REST API only)
* @prop {Number} oldGuild.mfaLevel The admin 2FA level for the guild. 0 is not required, 1 is required
* @prop {String} oldGuild.name The name of the guild
* @prop {String} oldGuild.nsfw Whether the guild is designated as NSFW by Discord
* @prop {Boolean} oldGuild.nsfw Whether the guild is designated as NSFW by Discord
* @prop {String} oldGuild.ownerID The ID of the user that is the guild owner
* @prop {String} oldGuild.preferredLocale Preferred "COMMUNITY" guild language used in server discovery and notices from Discord
* @prop {String?} oldGuild.publicUpdatesChannelID ID of the guild's updates channel if the guild has "COMMUNITY" features
Expand Down
2 changes: 1 addition & 1 deletion lib/rest/RequestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ class RequestHandler {
route = method + route;
}
if(method === "PUT" || method === "DELETE") {
let index = route.indexOf("/reactions");
const index = route.indexOf("/reactions");
if(index !== -1) {
route = "MODIFY" + route.slice(0, index + 10);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/structures/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class Base {
return Base.getCreatedAt(this.id);
}

static getCreatedAt(id) {
return Math.floor(id / 4194304) + 1420070400000;
}

[util.inspect.custom]() {
// http://stackoverflow.com/questions/5905492/dynamic-function-name-in-javascript
const copy = new {[this.constructor.name]: class {}}[this.constructor.name]();
Expand Down Expand Up @@ -53,10 +57,6 @@ class Base {
}
return json;
}

static getCreatedAt(id) {
return Math.floor(id / 4194304) + 1420070400000;
}
}

module.exports = Base;
7 changes: 3 additions & 4 deletions lib/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,8 @@ class Guild extends Base {
}

/**
* Modify a guild's vanity code
* @arg {String} code The new vanity code
* Modify the guild's vanity code
* @arg {String?} code The new vanity code
* @returns {Promise<Object>}
*/
editVanity(code) {
Expand All @@ -623,13 +623,12 @@ class Guild extends Base {
* @param {String} [userID="@me"] The user ID of the user to update
* @returns {Promise}
*/
editVoiceState(options, userID = "@me") {
editVoiceState(options, userID) {
return this._client.editGuildVoiceState.call(this._client, this.id, options, userID);
}

/**
* Edit the guild welcome screen
* @arg {String} guildID The ID of the guild
* @arg {Object} [options] The properties to edit
* @arg {String?} [options.description] The description in the welcome screen
* @arg {Boolean} [options.enabled] Whether the welcome screen is enabled
Expand Down
8 changes: 4 additions & 4 deletions lib/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const User = require("./User");
* @prop {Object?} interaction An object containing info about the interaction the message is responding to, if applicable
* @prop {String} interaction.id The id of the interaction
* @prop {Number} interaction.type The type of interaction
* @prop {Number} interaction.name The name of the command
* @prop {String} interaction.name The name of the command
* @prop {User} interaction.user The user who invoked the interaction
* @prop {Member?} interaction.member The member who invoked the interaction
* @prop {Boolean} pinned Whether the message is pinned or not
Expand Down Expand Up @@ -112,10 +112,10 @@ class Message extends Base {
}
this.interaction = {
id: data.interaction.id,
type: data.interaction.type,
member: interactionMember,
name: data.interaction.name,
user: interactionUser,
member: interactionMember
type: data.interaction.type,
user: interactionUser
};
} else {
this.interaction = null;
Expand Down
Loading

0 comments on commit 340ffe9

Please sign in to comment.