mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-02 21:16:09 +00:00
shorters
This commit is contained in:
parent
870e18a056
commit
6d47f6ee17
@ -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 }>;
|
||||
|
@ -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),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user