follow and cross post endpoints support

This commit is contained in:
Skillz
2020-08-31 15:59:31 -04:00
parent 090921b9e6
commit 7a09d9989e
4 changed files with 41 additions and 0 deletions

View File

@@ -45,6 +45,10 @@ export const endpoints = {
`${baseEndpoints.BASE_URL}/channels/${id}/messages/${messageID}/reactions`,
CHANNEL_MESSAGE_REACTION: (id: string, messageID: string, emoji: string) =>
`${baseEndpoints.BASE_URL}/channels/${id}/messages/${messageID}/reactions/${emoji}`,
CHANNEL_FOLLOW: (id: string) =>
`${baseEndpoints.BASE_URL}/channels/${id}/followers`,
CHANNEL_MESSAGE_CROSSPOST: (id: string, messageID: string) =>
`${baseEndpoints.BASE_URL}/channels/${id}/messages/${messageID}/crosspost`,
// Guild Endpoints
GUILD: (id: string) => `${GUILDS_BASE(id)}`,

View File

@@ -17,6 +17,7 @@ import {
MessageContent,
CreateInviteOptions,
ChannelEditOptions,
FollowedChannelPayload,
} from "../types/channel.ts";
import { logYellow } from "../utils/logger.ts";
@@ -340,3 +341,24 @@ export function editChannel(channel: Channel, options: ChannelEditOptions) {
payload,
);
}
/** Follow a News Channel to send messages to a target channel. Requires the `MANAGE_WEBHOOKS` permission in the target channel. Returns the webhook id. */
export async function followChannel(
sourceChannelID: string,
targetChannelID: string,
) {
if (
!botHasChannelPermissions(targetChannelID, [Permissions.MANAGE_WEBHOOKS])
) {
throw new Error(Errors.MISSING_MANAGE_CHANNELS);
}
const data = await RequestManager.post(
endpoints.CHANNEL_FOLLOW(sourceChannelID),
{
webhook_channel_id: targetChannelID,
},
) as FollowedChannelPayload;
return data.webhook_id;
}

View File

@@ -223,3 +223,11 @@ export async function editMessage(
);
return createMessage(result as MessageCreateOptions);
}
export async function publishMessage(channelID: string, messageID: string) {
const data = await RequestManager.post(
endpoints.CHANNEL_MESSAGE_CROSSPOST(channelID, messageID),
) as MessageCreateOptions;
return createMessage(data);
}

View File

@@ -146,3 +146,10 @@ export interface CreateInviteOptions {
/** If true, don't try to reuse a similar invite (useful for creating many unique one time use invites.) */
unique: boolean;
}
export interface FollowedChannelPayload {
/** The source channel id */
channel_id: string;
/** The webhook id */
webhook_id: string;
}