From 6d47f6ee17da08466f2227cea7941368c314cdfc Mon Sep 17 00:00:00 2001 From: MARCROCK22 <57925328+MARCROCK22@users.noreply.github.com> Date: Mon, 18 Mar 2024 19:40:31 -0400 Subject: [PATCH] shorters --- src/common/shorters/webhook.ts | 17 +++++++++++++++++ src/structures/channels.ts | 18 +++--------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/common/shorters/webhook.ts b/src/common/shorters/webhook.ts index cb4b3bb..8b5aa25 100644 --- a/src/common/shorters/webhook.ts +++ b/src/common/shorters/webhook.ts @@ -1,6 +1,7 @@ import type { RESTPatchAPIWebhookJSONBody, RESTPatchAPIWebhookWithTokenJSONBody, + RESTPostAPIChannelWebhookJSONBody, RESTPostAPIWebhookWithTokenJSONBody, } from '..'; import { resolveFiles } from '../../builders'; @@ -14,6 +15,12 @@ import { import { BaseShorter } from './base'; export class WebhookShorter extends BaseShorter { + async create(channelId: string, body: RESTPostAPIChannelWebhookJSONBody) { + const webhook = await this.client.proxy.channels(channelId).webhooks.post({ + body, + }); + return new Webhook(this.client, webhook); + } /** * Deletes a webhook. * @param webhookId The ID of the webhook. @@ -128,6 +135,16 @@ export class WebhookShorter extends BaseShorter { .get({ auth: false, query: { threadId } }); return message ? new WebhookMessage(this.client, message, webhookId, token) : undefined; } + + async listFromGuild(guildId: string) { + const webhooks = await this.client.proxy.guilds(guildId).webhooks.get(); + return webhooks.map(webhook => new Webhook(this.client, webhook)); + } + + async listFromChannel(channelId: string) { + const webhooks = await this.client.proxy.channels(channelId).webhooks.get(); + return webhooks.map(webhook => new Webhook(this.client, webhook)); + } } export type WebhookShorterOptionalParams = Partial<{ token: string; reason: string }>; diff --git a/src/structures/channels.ts b/src/structures/channels.ts index fd92bff..0746820 100644 --- a/src/structures/channels.ts +++ b/src/structures/channels.ts @@ -37,7 +37,6 @@ import type { } from '../common'; import type { GuildMember } from './GuildMember'; import type { GuildRole } from './GuildRole'; -import { Webhook } from './Webhook'; import { DiscordBase } from './extra/DiscordBase'; import { channelLink } from './extra/functions'; @@ -353,10 +352,7 @@ export class WebhookGuildMethods extends DiscordBase { static guild(ctx: MethodContext<{ guildId: string }>) { return { - list: async () => { - const webhooks = await ctx.client.proxy.guilds(ctx.guildId).webhooks.get(); - return webhooks.map(webhook => new Webhook(ctx.client, webhook)); - }, + list: () => ctx.client.webhooks.listFromChannel(ctx.guildId), }; } } @@ -366,16 +362,8 @@ export class WebhookChannelMethods extends DiscordBase { static channel(ctx: MethodContext<{ channelId: string }>) { return { - list: async () => { - const webhooks = await ctx.client.proxy.channels(ctx.channelId).webhooks.get(); - return webhooks.map(webhook => new Webhook(ctx.client, webhook)); - }, - create: async (body: RESTPostAPIChannelWebhookJSONBody) => { - const webhook = await ctx.client.proxy.channels(ctx.channelId).webhooks.post({ - body, - }); - return new Webhook(ctx.client, webhook); - }, + list: () => ctx.client.webhooks.listFromChannel(ctx.channelId), + create: async (body: RESTPostAPIChannelWebhookJSONBody) => ctx.client.webhooks.create(ctx.channelId, body), }; } }