Skip to content

Commit

Permalink
Add support for following NewsChannels (#948)
Browse files Browse the repository at this point in the history
Co-authored-by: abal <hi@abal.moe>
  • Loading branch information
bsian03 and abalabahaha committed May 19, 2020
1 parent 92f9cb3 commit 7d9f68c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,11 @@ declare namespace Eris {
(event: "resume", listener: () => void): T;
}

interface ChannelFollow {
channel_id: string;
webhook_id: string;
}

export class Client extends EventEmitter {
token?: string;
gatewayURL?: string;
Expand Down Expand Up @@ -1112,6 +1117,7 @@ declare namespace Eris {
reason?: string
): Promise<number>;
crosspostMessage(channelID: string, messageID: string): Promise<Message>;
followChannel(channelID: string, webhookChannelID: string): Promise<ChannelFollow>;
getGuildEmbed(guildID: string): Promise<GuildEmbed>;
getGuildPreview(guildID: string): Promise<GuildPreview>;
getGuildIntegrations(guildID: string): Promise<GuildIntegration[]>;
Expand Down Expand Up @@ -1594,6 +1600,7 @@ declare namespace Eris {
rateLimitPerUser: 0;
messages: Collection<Message<NewsChannel>>;
crosspostMessage(messageID: string): Promise<Message<NewsChannel>>;
follow(webhookChannelID: string): Promise<ChannelFollow>;
getMessage(messageID: string): Promise<Message<NewsChannel>>;
getMessages(limit?: number, before?: string, after?: string, around?: string): Promise<Message<NewsChannel>[]>;
getPins(): Promise<Message<NewsChannel>[]>;
Expand Down
10 changes: 10 additions & 0 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,16 @@ class Client extends EventEmitter {
return this.requestHandler.request("POST", Endpoints.CHANNEL_CROSSPOST(channelID, messageID), true).then((message) => new Message(message, this));
}

/**
* Follow a NewsChannel in another channel. This creates a webhook in the target channel
* @param {String} channelID The ID of the NewsChannel
* @arg {String} webhookChannelID The ID of the target channel
* @returns {Object} An object containing the NewsChannel's ID and the new webhook's ID
*/
followChannel(channelID, webhookChannelID) {
return this.requestHandler.request("POST", Endpoints.CHANNEL_FOLLOW(channelID), true, {webhook_channel_id: webhookChannelID});
}

/**
* Purge previous messages in a channel with an optional filter (bot accounts only)
* @arg {String} channelID The ID of the channel
Expand Down
1 change: 1 addition & 0 deletions lib/rest/Endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports.CHANNEL = (chanID)
module.exports.CHANNEL_BULK_DELETE = (chanID) => `/channels/${chanID}/messages/bulk-delete`;
module.exports.CHANNEL_CALL_RING = (chanID) => `/channels/${chanID}/call/ring`;
module.exports.CHANNEL_CROSSPOST = (chanID, msgID) => `/channels/${chanID}/messages/${msgID}/crosspost`;
module.exports.CHANNEL_FOLLOW = (chanID) => `/channels/${chanID}/followers`;
module.exports.CHANNEL_INVITES = (chanID) => `/channels/${chanID}/invites`;
module.exports.CHANNEL_MESSAGE_REACTION = (chanID, msgID, reaction) => `/channels/${chanID}/messages/${msgID}/reactions/${reaction}`;
module.exports.CHANNEL_MESSAGE_REACTION_USER = (chanID, msgID, reaction, userID) => `/channels/${chanID}/messages/${msgID}/reactions/${reaction}/${userID}`;
Expand Down
9 changes: 9 additions & 0 deletions lib/structures/NewsChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ class NewsChannel extends TextChannel {
crosspostMessage(messageID) {
return this.client.crosspostMessage.call(this.client, this.id, messageID);
}

/**
* Follow this channel in another channel. This creates a webhook in the target channel
* @arg {String} webhookChannelID The ID of the target channel
* @returns {Object} An object containing this channel's ID and the new webhook's ID
*/
follow(webhookChannelID) {
return this.client.followChannel.call(this.client, this.id, webhookChannelID);
}
}

module.exports = NewsChannel;

0 comments on commit 7d9f68c

Please sign in to comment.