Skip to content

Commit

Permalink
Merge branch 'dev' into concurSharding
Browse files Browse the repository at this point in the history
  • Loading branch information
DonovanDMC authored Jun 2, 2022
2 parents c204a5f + 2712a85 commit ac99a15
Show file tree
Hide file tree
Showing 18 changed files with 411 additions and 78 deletions.
1 change: 1 addition & 0 deletions esm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const {
StageInstance,
StoreChannel,
TextChannel,
TextVoiceChannel,
ThreadChannel,
ThreadMember,
UnavailableGuild,
Expand Down
102 changes: 68 additions & 34 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EventEmitter } from "events";
import { Duplex, Readable as ReadableStream, Stream } from "stream";
import { Agent as HTTPSAgent } from "https";
import { IncomingMessage, ClientRequest } from "http";
import { IncomingMessage, ClientRequest, IncomingHttpHeaders } from "http";
import OpusScript = require("opusscript"); // Thanks TypeScript
import { URL } from "url";
import { Socket as DgramSocket } from "dgram";
Expand Down Expand Up @@ -52,8 +52,8 @@ declare namespace Eris {
type AnyChannel = AnyGuildChannel | PrivateChannel;
type AnyGuildChannel = GuildTextableChannel | AnyVoiceChannel | CategoryChannel | StoreChannel;
type AnyThreadChannel = NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel | ThreadChannel;
type AnyVoiceChannel = VoiceChannel | StageChannel;
type GuildTextableChannel = TextChannel | NewsChannel;
type AnyVoiceChannel = TextVoiceChannel | StageChannel;
type GuildTextableChannel = TextChannel | TextVoiceChannel | NewsChannel;
type GuildTextableWithThread = GuildTextableChannel | AnyThreadChannel;
type InviteChannel = InvitePartialChannel | Exclude<AnyGuildChannel, CategoryChannel | AnyThreadChannel>;
type PossiblyUncachedTextable = Textable | Uncached;
Expand All @@ -66,8 +66,8 @@ declare namespace Eris {
type GuildTextChannelTypes = Constants["ChannelTypes"][keyof Pick<Constants["ChannelTypes"], "GUILD_TEXT" | "GUILD_NEWS">];
type GuildThreadChannelTypes = Constants["ChannelTypes"][keyof Pick<Constants["ChannelTypes"], "GUILD_NEWS_THREAD" | "GUILD_PRIVATE_THREAD" | "GUILD_PUBLIC_THREAD">];
type GuildPublicThreadChannelTypes = Exclude<GuildThreadChannelTypes, Constants["ChannelTypes"]["GUILD_PRIVATE_THREAD"]>;
type GuildVoiceChannelTypes = Constants["ChannelTypes"][keyof Pick<Constants["ChannelTypes"], "GUILD_VOICE" | "GUILD_STAGE">];
type PrivateChannelTypes = Constants["ChannelTypes"][keyof Pick<Constants["ChannelTypes"], "DM" | "GROUP_DM">];
type TextVoiceChannelTypes = Constants["ChannelTypes"][keyof Pick<Constants["ChannelTypes"], "GUILD_VOICE" | "GUILD_STAGE">];

// Command
type CommandGenerator = CommandGeneratorFunction | MessageContent | MessageContent[] | CommandGeneratorFunction[];
Expand Down Expand Up @@ -293,10 +293,12 @@ declare namespace Eris {
before?: string;
limit?: number;
}
interface GuildTextable extends Textable {
interface GuildPinnable extends Pinnable {
lastPinTimestamp: number | null;
topic?: string | null;
}
interface GuildTextable extends Textable {
rateLimitPerUser: number;
topic: string | null;
createWebhook(options: { name: string; avatar?: string | null }, reason?: string): Promise<Webhook>;
deleteMessages(messageIDs: string[], reason?: string): Promise<void>;
getWebhooks(): Promise<Webhook[]>;
Expand All @@ -316,6 +318,11 @@ declare namespace Eris {
type: number;
user_limit?: number;
}
interface Pinnable {
getPins(): Promise<Message[]>;
pinMessage(messageID: string): Promise<void>;
unpinMessage(messageID: string): Promise<void>;
}
interface PurgeChannelOptions {
after?: string;
before?: string;
Expand All @@ -339,14 +346,12 @@ declare namespace Eris {
getMessages(options?: GetMessagesOptions): Promise<Message<this>[]>;
/** @deprecated */
getMessages(limit?: number, before?: string, after?: string, around?: string): Promise<Message[]>;
getPins(): Promise<Message[]>;
pinMessage(messageID: string): Promise<void>;
removeMessageReaction(messageID: string, reaction: string, userID?: string): Promise<void>;
sendTyping(): Promise<void>;
unpinMessage(messageID: string): Promise<void>;
unsendMessage(messageID: string): Promise<void>;
}
interface ThreadTextable extends Textable {
// @ts-ignore ts(2430) - ThreadTextable can't properly extend Textable because of getMessageReaction deprecated overload
interface ThreadTextable extends Textable, Pinnable {
lastPinTimestamp?: number;
deleteMessages(messageIDs: string[], reason?: string): Promise<void>;
getMembers(): Promise<ThreadMember[]>;
Expand Down Expand Up @@ -621,19 +626,12 @@ declare namespace Eris {
topic: string | null;
type: GuildTextChannelTypes;
}
interface OldGuildVoiceChannel extends OldGuildChannel {
bitrate: number;
rtcRegion: string | null;
type: GuildVoiceChannelTypes;
userLimit: number;
videoQualityMode: VideoQualityMode;
}
interface OldMember {
avatar: string | null;
communicationDisabledUntil: number | null;
nick: string | null;
pending?: boolean;
premiumSince: number;
premiumSince?: number | null;
roles: string[];
}
interface OldMessage {
Expand Down Expand Up @@ -665,6 +663,13 @@ declare namespace Eris {
privacyLevel: StageInstancePrivacyLevel;
topic: string;
}
interface OldTextVoiceChannel extends OldGuildChannel {
bitrate: number;
rtcRegion: string | null;
type: TextVoiceChannelTypes;
userLimit: number;
videoQualityMode: VideoQualityMode;
}
interface OldThread {
name: string;
rateLimitPerUser: number;
Expand All @@ -686,12 +691,12 @@ declare namespace Eris {
callDelete: [call: Call];
callRing: [call: Call];
callUpdate: [call: Call, oldCall: OldCall];
channelCreate: [channel: AnyChannel];
channelCreate: [channel: AnyGuildChannel];
channelDelete: [channel: AnyChannel];
channelPinUpdate: [channel: TextableChannel, timestamp: number, oldTimestamp: number];
channelRecipientAdd: [channel: GroupChannel, user: User];
channelRecipientRemove: [channel: GroupChannel, user: User];
channelUpdate: [channel: AnyGuildChannel, oldChannel: OldGuildChannel | OldGuildTextChannel | OldGuildVoiceChannel]
channelUpdate: [channel: AnyGuildChannel, oldChannel: OldGuildChannel | OldGuildTextChannel | OldTextVoiceChannel]
| [channel: GroupChannel, oldChannel: OldGroupChannel];
connect: [id: number];
debug: [message: string, id?: number];
Expand Down Expand Up @@ -1811,10 +1816,10 @@ declare namespace Eris {
sendMessagesInThreads: 274877906944n;
startEmbeddedActivities: 549755813888n;
moderateMembers: 1099511627776n;
allGuild: 1101592527038n;
allText: 518349388881n;
allGuild: 1110182461630n;
allText: 535529258065n;
allVoice: 554385278737n;
all: 1228360646655n;
all: 2199023255551n;
};
PremiumTiers: {
NONE: 0;
Expand Down Expand Up @@ -2134,7 +2139,7 @@ declare namespace Eris {
name: string,
type: Constants["ChannelTypes"]["GUILD_VOICE"],
options?: CreateChannelOptions
): Promise<VoiceChannel>;
): Promise<TextVoiceChannel>;
createChannel(
guildID: string,
name: string,
Expand Down Expand Up @@ -2180,7 +2185,7 @@ declare namespace Eris {
type: Constants["ChannelTypes"]["GUILD_VOICE"],
reason?: string,
options?: CreateChannelOptions | string
): Promise<VoiceChannel>;
): Promise<TextVoiceChannel>;
/** @deprecated */
createChannel(
guildID: string,
Expand Down Expand Up @@ -2572,6 +2577,7 @@ declare namespace Eris {

export class DiscordHTTPError extends Error {
code: number;
headers: IncomingHttpHeaders;
name: "DiscordHTTPError";
req: ClientRequest;
res: IncomingMessage;
Expand All @@ -2582,6 +2588,7 @@ declare namespace Eris {

export class DiscordRESTError extends Error {
code: number;
headers: IncomingHttpHeaders;
name: string;
req: ClientRequest;
res: IncomingMessage;
Expand Down Expand Up @@ -2676,7 +2683,7 @@ declare namespace Eris {
bulkEditCommands(commands: ApplicationCommandStructure[]): Promise<ApplicationCommand[]>;
createChannel(name: string): Promise<TextChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_TEXT"], options?: CreateChannelOptions): Promise<TextChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_VOICE"], options?: CreateChannelOptions): Promise<VoiceChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_VOICE"], options?: CreateChannelOptions): Promise<TextVoiceChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_CATEGORY"], options?: CreateChannelOptions): Promise<CategoryChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_NEWS"], options?: CreateChannelOptions | string): Promise<NewsChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_STORE"], options?: CreateChannelOptions | string): Promise<StoreChannel>;
Expand All @@ -2685,7 +2692,7 @@ declare namespace Eris {
/** @deprecated */
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_TEXT"], reason?: string, options?: CreateChannelOptions | string): Promise<TextChannel>;
/** @deprecated */
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_VOICE"], reason?: string, options?: CreateChannelOptions | string): Promise<VoiceChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_VOICE"], reason?: string, options?: CreateChannelOptions | string): Promise<TextVoiceChannel>;
/** @deprecated */
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_CATEGORY"], reason?: string, options?: CreateChannelOptions | string): Promise<CategoryChannel>;
/** @deprecated */
Expand Down Expand Up @@ -2882,6 +2889,33 @@ declare namespace Eris {
toJSON(props?: string[]): JSONCache;
}

export class TextVoiceChannel extends VoiceChannel implements GuildTextable {
lastMessageID: string;
messages: Collection<Message<this>>;
rateLimitPerUser: number;
addMessageReaction(messageID: string, reaction: string): Promise<void>;
/** @deprecated */
addMessageReaction(messageID: string, reaction: string, userID: string): Promise<void>;
createMessage(content: MessageContent, file?: FileContent | FileContent[]): Promise<Message<this>>;
createWebhook(options: { name: string; avatar?: string | null }, reason?: string): Promise<Webhook>;
deleteMessage(messageID: string, reason?: string): Promise<void>;
deleteMessages(messageIDs: string[], reason?: string): Promise<void>;
editMessage(messageID: string, content: MessageContentEdit): Promise<Message<this>>;
getMessage(messageID: string): Promise<Message<this>>;
getMessageReaction(messageID: string, reaction: string, options?: GetMessageReactionOptions): Promise<User[]>;
/** @deprecated */
getMessageReaction(messageID: string, reaction: string, limit?: number, before?: string, after?: string): Promise<User[]>;
getMessages(options?: GetMessagesOptions): Promise<Message<this>[]>;
/** @deprecated */
getMessages(limit?: number, before?: string, after?: string, around?: string): Promise<Message[]>;
getWebhooks(): Promise<Webhook[]>;
purge(options: PurgeChannelOptions): Promise<number>;
removeMessageReaction(messageID: string, reaction: string, userID?: string): Promise<void>;
removeMessageReactionEmoji(messageID: string, reaction: string): Promise<void>;
removeMessageReactions(messageID: string): Promise<void>;
sendTyping(): Promise<void>;
unsendMessage(messageID: string): Promise<void>;
}
export class Interaction extends Base {
acknowledged: boolean;
applicationID: string;
Expand Down Expand Up @@ -3048,7 +3082,7 @@ declare namespace Eris {
/** @deprecated */
permission: Permission;
permissions: Permission;
premiumSince: number;
premiumSince?: number | null;
roles: string[];
staticAvatarURL: string;
status?: Status;
Expand Down Expand Up @@ -3122,7 +3156,7 @@ declare namespace Eris {
}

// News channel rate limit is always 0
export class NewsChannel extends TextChannel {
export class NewsChannel extends TextChannel implements GuildPinnable {
rateLimitPerUser: 0;
type: Constants["ChannelTypes"]["GUILD_NEWS"];
createInvite(options?: CreateInviteOptions, reason?: string): Promise<Invite<"withMetadata", this>>;
Expand All @@ -3148,7 +3182,7 @@ declare namespace Eris {
deny: bigint;
json: Record<keyof Constants["Permissions"], boolean>;
constructor(allow: number | string | bigint, deny?: number | string | bigint);
has(permission: keyof Constants["Permissions"]): boolean;
has(permission: keyof Constants["Permissions"] | bigint): boolean;
}

export class PermissionOverwrite extends Permission {
Expand All @@ -3175,7 +3209,7 @@ declare namespace Eris {
stop(e: Error, source: Duplex): void;
}

export class PrivateChannel extends Channel implements Textable {
export class PrivateChannel extends Channel implements Textable, Pinnable {
lastMessageID: string;
messages: Collection<Message<this>>;
recipient: User;
Expand Down Expand Up @@ -3410,13 +3444,13 @@ declare namespace Eris {
edit(options: Omit<EditChannelOptions, "icon" | "ownerID">, reason?: string): Promise<this>;
}

export class TextChannel extends GuildChannel implements GuildTextable, Invitable {
export class TextChannel extends GuildChannel implements GuildTextable, Invitable, GuildPinnable {
defaultAutoArchiveDuration: AutoArchiveDuration;
lastMessageID: string;
lastPinTimestamp: number | null;
messages: Collection<Message<this>>;
rateLimitPerUser: number;
topic: string | null;
topic?: string | null;
type: GuildTextChannelTypes;
constructor(data: BaseData, client: Client, messageLimit: number);
addMessageReaction(messageID: string, reaction: string): Promise<void>;
Expand Down Expand Up @@ -3547,7 +3581,7 @@ declare namespace Eris {
export class VoiceChannel extends GuildChannel implements Invitable {
bitrate: number;
rtcRegion: string | null;
type: GuildVoiceChannelTypes;
type: TextVoiceChannelTypes;
userLimit: number;
videoQualityMode: VideoQualityMode;
voiceMembers: Collection<Member>;
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Eris.StageChannel = require("./lib/structures/StageChannel");
Eris.StageInstance = require("./lib/structures/StageInstance");
Eris.StoreChannel = require("./lib/structures/StoreChannel");
Eris.TextChannel = require("./lib/structures/TextChannel");
Eris.TextVoiceChannel = require("./lib/structures/TextVoiceChannel");
Eris.ThreadChannel = require("./lib/structures/ThreadChannel");
Eris.ThreadMember = require("./lib/structures/ThreadMember");
Eris.UnavailableGuild = require("./lib/structures/UnavailableGuild");
Expand Down
16 changes: 8 additions & 8 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ class Client extends EventEmitter {
* @arg {String} [options.reason] The reason to be displayed in audit logs
* @arg {String} [options.topic] The topic of the channel (text channels only)
* @arg {Number} [options.userLimit] The channel user limit (voice channels only)
* @returns {Promise<CategoryChannel | TextChannel | VoiceChannel>}
* @returns {Promise<CategoryChannel | TextChannel | TextVoiceChannel>}
*/
createChannel(guildID, name, type, reason, options = {}) {
if(typeof options === "string") { // This used to be parentID, back-compat
Expand Down Expand Up @@ -1093,7 +1093,7 @@ class Client extends EventEmitter {
return Promise.resolve();
}
if(messageIDs.length === 1) {
return this.deleteMessage(channelID, messageIDs[0]);
return this.deleteMessage(channelID, messageIDs[0], reason);
}

const oldestAllowedSnowflake = (Date.now() - 1421280000000) * 4194304;
Expand All @@ -1106,7 +1106,7 @@ class Client extends EventEmitter {
return this.requestHandler.request("POST", Endpoints.CHANNEL_BULK_DELETE(channelID), true, {
messages: messageIDs.splice(0, 100),
reason: reason
}).then(() => this.deleteMessages(channelID, messageIDs));
}).then(() => this.deleteMessages(channelID, messageIDs, reason));
}
return this.requestHandler.request("POST", Endpoints.CHANNEL_BULK_DELETE(channelID), true, {
messages: messageIDs,
Expand Down Expand Up @@ -1248,7 +1248,7 @@ class Client extends EventEmitter {
* @arg {Number} [options.userLimit] The channel user limit (guild voice channels only)
* @arg {Number} [options.videoQualityMode] The camera video quality mode of the channel (guild voice channels only). `1` is auto, `2` is 720p
* @arg {String} [reason] The reason to be displayed in audit logs
* @returns {Promise<CategoryChannel | GroupChannel | TextChannel | VoiceChannel | NewsChannel | NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel>}
* @returns {Promise<CategoryChannel | GroupChannel | TextChannel | TextVoiceChannel | NewsChannel | NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel>}
*/
editChannel(channelID, options, reason) {
return this.requestHandler.request("PATCH", Endpoints.CHANNEL(channelID), true, {
Expand Down Expand Up @@ -1571,7 +1571,7 @@ class Client extends EventEmitter {
});
}
/**
* Update a user's voice state - See [caveats](https://discord.com/developers/docs/resources/guild#update-others-voice-state-caveats)
* Update a user's voice state - See [caveats](https://discord.com/developers/docs/resources/guild#modify-user-voice-state-caveats)
* @arg {String} guildID The ID of the guild
* @arg {Object} options The properties to edit
* @arg {String} options.channelID The ID of the channel the user is currently in
Expand Down Expand Up @@ -2147,7 +2147,7 @@ class Client extends EventEmitter {
/**
* Get a Channel object from a channel ID
* @arg {String} channelID The ID of the channel
* @returns {CategoryChannel | GroupChannel | PrivateChannel | TextChannel | VoiceChannel | NewsChannel | NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel}
* @returns {CategoryChannel | GroupChannel | PrivateChannel | TextChannel | TextVoiceChannel | NewsChannel | NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel}
*/
getChannel(channelID) {
if(!channelID) {
Expand Down Expand Up @@ -2661,7 +2661,7 @@ class Client extends EventEmitter {
/**
* Get a channel's data via the REST API. REST mode is required to use this endpoint.
* @arg {String} channelID The ID of the channel
* @returns {Promise<CategoryChannel | GroupChannel | PrivateChannel | TextChannel | VoiceChannel | NewsChannel | NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel>}
* @returns {Promise<CategoryChannel | GroupChannel | PrivateChannel | TextChannel | TextVoiceChannel | NewsChannel | NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel>}
*/
getRESTChannel(channelID) {
if(!this.options.restMode) {
Expand Down Expand Up @@ -2689,7 +2689,7 @@ class Client extends EventEmitter {
/**
* Get a guild's channels via the REST API. REST mode is required to use this endpoint.
* @arg {String} guildID The ID of the guild
* @returns {Promise<Array<CategoryChannel> | Array<TextChannel> | Array<VoiceChannel> | Array<NewsChannel>>}
* @returns {Promise<Array<CategoryChannel> | Array<TextChannel> | Array<TextVoiceChannel> | Array<NewsChannel>>}
*/
getRESTGuildChannels(guildID) {
if(!this.options.restMode) {
Expand Down
2 changes: 2 additions & 0 deletions lib/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ Permissions.allGuild = Permissions.kickMembers
| Permissions.manageRoles
| Permissions.manageWebhooks
| Permissions.manageEmojisAndStickers
| Permissions.manageEvents
| Permissions.moderateMembers;
Permissions.allText = Permissions.createInstantInvite
| Permissions.manageChannels
Expand All @@ -412,6 +413,7 @@ Permissions.allText = Permissions.createInstantInvite
| Permissions.manageRoles
| Permissions.manageWebhooks
| Permissions.useApplicationCommands
| Permissions.manageThreads
| Permissions.createPublicThreads
| Permissions.createPrivateThreads
| Permissions.useExternalStickers
Expand Down
4 changes: 4 additions & 0 deletions lib/errors/DiscordHTTPError.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class DiscordHTTPError extends Error {
}
}

get headers() {
return this.response.headers;
}

get name() {
return this.constructor.name;
}
Expand Down
Loading

0 comments on commit ac99a15

Please sign in to comment.