fix(handlers/channel): add permission handler for startTyping() (#626)

* add perm check

* Update src/api/handlers/channel.ts

Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>

Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>
This commit is contained in:
ITOH
2021-03-08 14:46:23 +01:00
committed by GitHub
parent ed85685d35
commit 100f7ff965

View File

@@ -133,6 +133,30 @@ export async function getPins(channelID: string) {
* this endpoint may be called to let the user know that the bot is processing their message.
*/
export async function startTyping(channelID: string) {
const channel = await cacheHandlers.get("channels", channelID);
// If the channel is cached, we can do extra checks/safety
if (channel) {
if (
![
ChannelTypes.DM,
ChannelTypes.GUILD_NEWS,
ChannelTypes.GUILD_TEXT,
].includes(channel.type)
) {
throw new Error(Errors.CHANNEL_NOT_TEXT_BASED);
}
const hasSendMessagesPerm = await botHasChannelPermissions(
channelID,
["SEND_MESSAGES"],
);
if (
!hasSendMessagesPerm
) {
throw new Error(Errors.MISSING_SEND_MESSAGES);
}
}
const result = await RequestManager.post(endpoints.CHANNEL_TYPING(channelID));
return result;