Skip to content

Commit

Permalink
fix(typings): normalize Textable, fix deprecations (#1299)
Browse files Browse the repository at this point in the history
  • Loading branch information
eritbh authored Nov 16, 2021
1 parent 9dd304b commit a4023da
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 63 deletions.
97 changes: 40 additions & 57 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ declare namespace Eris {
purge(options: PurgeChannelOptions): Promise<number>;
removeMessageReactionEmoji(messageID: string, reaction: string): Promise<void>;
removeMessageReactions(messageID: string): Promise<void>;
sendTyping(): Promise<void>;
}
interface PartialChannel {
bitrate?: number;
Expand All @@ -350,32 +349,32 @@ declare namespace Eris {
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>;
createMessage(content: MessageContent, file?: FileContent | FileContent[]): Promise<Message<this>>;
deleteMessage(messageID: string, reason?: string): Promise<void>;
editMessage(messageID: string, content: MessageContentEdit): Promise<Message>;
getMessage(messageID: string): Promise<Message>;
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[]>;
getMessages(options?: GetMessagesOptions): Promise<Message<this>[]>;
/** @deprecated */
getMessages(limit?: number, before?: string, after?: string, around?: string): Promise<Message[]>;
getPins(): Promise<Message[]>;
getMessages(limit?: number, before?: string, after?: string, around?: string): Promise<Message<this>[]>;
getPins(): Promise<Message<this>[]>;
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>;
}
// @ts-ignore ts(2430) - ThreadTextable can't properly extend Textable because of getMessageReaction deprecated overload
interface ThreadTextable extends Textable {
lastPinTimestamp?: number;
createMessage(content: MessageContent, file?: FileContent | FileContent[]): Promise<Message<ThreadChannel>>;
editMessage(messageID: string, content: MessageContentEdit): Promise<Message<ThreadChannel>>;
getMessage(messageID: string): Promise<Message<ThreadChannel>>;
getMessageReaction(messageID: string, reaction: string, options?: GetMessageReactionOptions): Promise<User[]>;
getMessages(options?: GetMessagesOptions): Promise<Message<ThreadChannel>[]>;
getPins(): Promise<Message<ThreadChannel>[]>;
deleteMessages(messageIDs: string[], reason?: string): Promise<void>;
getMembers(): Promise<ThreadMember[]>;
join(userID: string): Promise<void>;
leave(userID: string): Promise<void>;
purge(options: PurgeChannelOptions): Promise<number>;
removeMessageReactionEmoji(messageID: string, reaction: string): Promise<void>;
removeMessageReactions(messageID: string): Promise<void>;
}
interface WebhookData {
channelID: string;
Expand Down Expand Up @@ -3120,27 +3119,21 @@ declare namespace Eris {
rateLimitPerUser: 0;
type: Constants["ChannelTypes"]["GUILD_NEWS"];
createInvite(options?: CreateInviteOptions, reason?: string): Promise<Invite<"withMetadata", NewsChannel>>;
createMessage(content: MessageContent, file?: FileContent | FileContent[]): Promise<Message<NewsChannel>>;
createMessage(content: MessageContent, file?: FileContent | FileContent[]): Promise<Message<this>>;
createThreadWithMessage(messageID: string, options: CreateThreadOptions): Promise<NewsThreadChannel>;
crosspostMessage(messageID: string): Promise<Message<NewsChannel>>;
editMessage(messageID: string, content: MessageContentEdit): Promise<Message<NewsChannel>>;
editMessage(messageID: string, content: MessageContentEdit): Promise<Message<this>>;
follow(webhookChannelID: string): Promise<ChannelFollow>;
getInvites(): Promise<(Invite<"withMetadata", NewsChannel>)[]>;
getMessage(messageID: string): Promise<Message<NewsChannel>>;
getMessages(options?: GetMessagesOptions): Promise<Message<NewsChannel>[]>;
getMessage(messageID: string): Promise<Message<this>>;
getMessages(options?: GetMessagesOptions): Promise<Message<this>[]>;
/** @deprecated */
getMessages(limit?: number, before?: string, after?: string, around?: string): Promise<Message<NewsChannel>[]>;
getPins(): Promise<Message<NewsChannel>[]>;
getMessages(limit?: number, before?: string, after?: string, around?: string): Promise<Message<this>[]>;
getPins(): Promise<Message<this>[]>;
}

export class NewsThreadChannel extends ThreadChannel {
type: Constants["ChannelTypes"]["GUILD_NEWS_THREAD"];
createMessage(content: MessageContent, file?: FileContent | FileContent[]): Promise<Message<NewsThreadChannel>>;
edit(options: Pick<EditChannelOptions, "archived" | "autoArchiveDuration" | "locked" | "name" | "rateLimitPerUser">, reason?: string): Promise<this>;
editMessage(messageID: string, content: MessageContentEdit): Promise<Message<NewsThreadChannel>>;
getMessage(messageID: string): Promise<Message<NewsThreadChannel>>;
getMessages(options?: GetMessagesOptions): Promise<Message<NewsThreadChannel>[]>;
getPins(): Promise<Message<NewsThreadChannel>[]>;
}

export class Permission extends Base {
Expand Down Expand Up @@ -3183,17 +3176,17 @@ declare namespace Eris {
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<PrivateChannel>>;
createMessage(content: MessageContent, file?: FileContent | FileContent[]): Promise<Message<this>>;
deleteMessage(messageID: string, reason?: string): Promise<void>;
editMessage(messageID: string, content: MessageContentEdit): Promise<Message<PrivateChannel>>;
getMessage(messageID: string): Promise<Message<PrivateChannel>>;
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<PrivateChannel>[]>;
getMessages(options?: GetMessagesOptions): Promise<Message<this>[]>;
/** @deprecated */
getMessages(limit?: number, before?: string, after?: string, around?: string): Promise<Message<PrivateChannel>[]>;
getPins(): Promise<Message<PrivateChannel>[]>;
getMessages(limit?: number, before?: string, after?: string, around?: string): Promise<Message<this>[]>;
getPins(): Promise<Message<this>[]>;
leave(): Promise<void>;
pinMessage(messageID: string): Promise<void>;
removeMessageReaction(messageID: string, reaction: string): Promise<void>;
Expand All @@ -3209,22 +3202,11 @@ declare namespace Eris {
export class PrivateThreadChannel extends ThreadChannel {
threadMetadata: PrivateThreadMetadata;
type: Constants["ChannelTypes"]["GUILD_PRIVATE_THREAD"];
createMessage(content: MessageContent, file?: FileContent | FileContent[]): Promise<Message<PrivateThreadChannel>>;
edit(options: Pick<EditChannelOptions, "archived" | "autoArchiveDuration" | "invitable" | "locked" | "name" | "rateLimitPerUser">, reason?: string): Promise<this>;
editMessage(messageID: string, content: MessageContentEdit): Promise<Message<PrivateThreadChannel>>;
getMessage(messageID: string): Promise<Message<PrivateThreadChannel>>;
getMessages(options?: GetMessagesOptions): Promise<Message<PrivateThreadChannel>[]>;
getPins(): Promise<Message<PrivateThreadChannel>[]>;
}

export class PublicThreadChannel extends ThreadChannel {
type: GuildPublicThreadChannelTypes;
createMessage(content: MessageContent, file?: FileContent | FileContent[]): Promise<Message<PublicThreadChannel>>;
edit(options: Pick<EditChannelOptions, "archived" | "autoArchiveDuration" | "locked" | "name" | "rateLimitPerUser">, reason?: string): Promise<this>;
editMessage(messageID: string, content: MessageContentEdit): Promise<Message<PublicThreadChannel>>;
getMessage(messageID: string): Promise<Message<PublicThreadChannel>>;
getMessages(options?: GetMessagesOptions): Promise<Message<PublicThreadChannel>[]>;
getPins(): Promise<Message<PublicThreadChannel>[]>;
}

export class Relationship extends Base implements Omit<Presence, "activities"> {
Expand Down Expand Up @@ -3434,28 +3416,28 @@ declare namespace Eris {
/** @deprecated */
addMessageReaction(messageID: string, reaction: string, userID: string): Promise<void>;
createInvite(options?: CreateInviteOptions, reason?: string): Promise<Invite<"withMetadata", TextChannel>>;
createMessage(content: MessageContent, file?: FileContent | FileContent[]): Promise<Message<TextChannel>>;
createMessage(content: MessageContent, file?: FileContent | FileContent[]): Promise<Message<this>>;
createThreadWithMessage(messageID: string, options: CreateThreadOptions): Promise<PublicThreadChannel>;
createThreadWithoutMessage(options: CreateThreadWithoutMessageOptions): Promise<PrivateThreadChannel>;
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>;
edit(options: Omit<EditChannelOptions, "icon" | "ownerID">, reason?: string): Promise<this>;
editMessage(messageID: string, content: MessageContentEdit): Promise<Message<TextChannel>>;
editMessage(messageID: string, content: MessageContentEdit): Promise<Message<this>>;
/** @deprecated */
getActiveThreads(): Promise<ListedChannelThreads>;
getArchivedThreads(type: "private", options?: GetArchivedThreadsOptions): Promise<ListedChannelThreads<PrivateThreadChannel>>;
getArchivedThreads(type: "public", options?: GetArchivedThreadsOptions): Promise<ListedChannelThreads<PublicThreadChannel>>;
getInvites(): Promise<(Invite<"withMetadata", TextChannel>)[]>;
getJoinedPrivateArchivedThreads(options: GetArchivedThreadsOptions): Promise<ListedChannelThreads<PrivateThreadChannel>>;
getMessage(messageID: string): Promise<Message<TextChannel>>;
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<TextChannel>[]>;
getMessages(options?: GetMessagesOptions): Promise<Message<this>[]>;
/** @deprecated */
getMessages(limit?: number, before?: string, after?: string, around?: string): Promise<Message<TextChannel>[]>;
getPins(): Promise<Message<TextChannel>[]>;
getMessages(limit?: number, before?: string, after?: string, around?: string): Promise<Message<this>[]>;
getPins(): Promise<Message<this>[]>;
getWebhooks(): Promise<Webhook[]>;
pinMessage(messageID: string): Promise<void>;
purge(options: PurgeChannelOptions): Promise<number>;
Expand All @@ -3469,9 +3451,6 @@ declare namespace Eris {
unsendMessage(messageID: string): Promise<void>;
}

type A<T extends TextableChannel> = T;
type B = A<PublicThreadChannel>;

export class ThreadChannel extends GuildChannel implements ThreadTextable {
lastMessageID: string;
lastPinTimestamp?: number;
Expand All @@ -3486,16 +3465,20 @@ declare namespace Eris {
type: GuildThreadChannelTypes;
constructor(data: BaseData, client: Client, messageLimit?: number);
addMessageReaction(messageID: string, reaction: string): Promise<void>;
createMessage(content: MessageContent, file?: FileContent | FileContent[]): Promise<Message<ThreadChannel>>;
createMessage(content: MessageContent, file?: FileContent | FileContent[]): Promise<Message<this>>;
deleteMessage(messageID: string, reason?: string): Promise<void>;
deleteMessages(messageIDs: string[], reason?: string): Promise<void>;
edit(options: Pick<EditChannelOptions, "archived" | "autoArchiveDuration" | "invitable" | "locked" | "name" | "rateLimitPerUser">, reason?: string): Promise<this>;
editMessage(messageID: string, content: MessageContentEdit): Promise<Message<ThreadChannel>>;
editMessage(messageID: string, content: MessageContentEdit): Promise<Message<this>>;
getMembers(): Promise<ThreadMember[]>;
getMessage(messageID: string): Promise<Message<ThreadChannel>>;
getMessage(messageID: string): Promise<Message<this>>;
getMessageReaction(messageID: string, reaction: string, options?: GetMessageReactionOptions): Promise<User[]>;
getMessages(options?: GetMessagesOptions): Promise<Message<ThreadChannel>[]>;
getPins(): Promise<Message<ThreadChannel>[]>;
/** @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<this>[]>;
getPins(): Promise<Message<this>[]>;
join(userID?: string): Promise<void>;
leave(userID?: string): Promise<void>;
pinMessage(messageID: string): Promise<void>;
Expand Down
17 changes: 11 additions & 6 deletions lib/structures/ThreadChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,26 +194,31 @@ class ThreadChannel extends GuildChannel {
* Get a list of users who reacted with a specific reaction
* @arg {String} messageID The ID of the message
* @arg {String} reaction The reaction (Unicode string if Unicode emoji, `emojiName:emojiID` if custom emoji)
* @arg {Object} [options] Options for the request.
* @arg {Object} [options] Options for the request. If this is a number, it is treated as `options.limit` ([DEPRECATED] behavior)
* @arg {Number} [options.limit=100] The maximum number of users to get
* @arg {String} [options.after] Get users after this user ID
* @arg {String} [before] [DEPRECATED] Get users before this user ID. Discord no longer supports this parameter
* @arg {String} [after] [DEPRECATED] Get users after this user ID
* @returns {Promise<Array<User>>}
*/
getMessageReaction(messageID, reaction, options) {
return this.client.getMessageReaction.call(this.client, this.id, messageID, reaction, options);
getMessageReaction(messageID, reaction, options, before, after) {
return this.client.getMessageReaction.call(this.client, this.id, messageID, reaction, options, before, after);
}

/**
* Get previous messages in the channel
* @arg {Object} [options] Options for the request
* @arg {Object} [options] Options for the request. If this is a number ([DEPRECATED] behavior), it is treated as `options.limit`
* @arg {String} [options.after] Get messages after this message ID
* @arg {String} [options.around] Get messages around this message ID (does not work with limit > 100)
* @arg {String} [options.before] Get messages before this message ID
* @arg {Number} [options.limit=50] The max number of messages to get
* @arg {String} [before] [DEPRECATED] Get messages before this message ID
* @arg {String} [after] [DEPRECATED] Get messages after this message ID
* @arg {String} [around] [DEPRECATED] Get messages around this message ID (does not work with limit > 100)
* @returns {Promise<Array<Message>>}
*/
getMessages(options) {
return this.client.getMessages.call(this.client, this.id, options);
getMessages(options, before, after, around) {
return this.client.getMessages.call(this.client, this.id, options, before, after, around);
}

/**
Expand Down

0 comments on commit a4023da

Please sign in to comment.