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 {
|
import type {
|
||||||
RESTPatchAPIWebhookJSONBody,
|
RESTPatchAPIWebhookJSONBody,
|
||||||
RESTPatchAPIWebhookWithTokenJSONBody,
|
RESTPatchAPIWebhookWithTokenJSONBody,
|
||||||
|
RESTPostAPIChannelWebhookJSONBody,
|
||||||
RESTPostAPIWebhookWithTokenJSONBody,
|
RESTPostAPIWebhookWithTokenJSONBody,
|
||||||
} from '..';
|
} from '..';
|
||||||
import { resolveFiles } from '../../builders';
|
import { resolveFiles } from '../../builders';
|
||||||
@ -14,6 +15,12 @@ import {
|
|||||||
import { BaseShorter } from './base';
|
import { BaseShorter } from './base';
|
||||||
|
|
||||||
export class WebhookShorter extends BaseShorter {
|
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.
|
* Deletes a webhook.
|
||||||
* @param webhookId The ID of the webhook.
|
* @param webhookId The ID of the webhook.
|
||||||
@ -128,6 +135,16 @@ export class WebhookShorter extends BaseShorter {
|
|||||||
.get({ auth: false, query: { threadId } });
|
.get({ auth: false, query: { threadId } });
|
||||||
return message ? new WebhookMessage(this.client, message, webhookId, token) : undefined;
|
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 }>;
|
export type WebhookShorterOptionalParams = Partial<{ token: string; reason: string }>;
|
||||||
|
@ -37,7 +37,6 @@ import type {
|
|||||||
} from '../common';
|
} from '../common';
|
||||||
import type { GuildMember } from './GuildMember';
|
import type { GuildMember } from './GuildMember';
|
||||||
import type { GuildRole } from './GuildRole';
|
import type { GuildRole } from './GuildRole';
|
||||||
import { Webhook } from './Webhook';
|
|
||||||
import { DiscordBase } from './extra/DiscordBase';
|
import { DiscordBase } from './extra/DiscordBase';
|
||||||
import { channelLink } from './extra/functions';
|
import { channelLink } from './extra/functions';
|
||||||
|
|
||||||
@ -353,10 +352,7 @@ export class WebhookGuildMethods extends DiscordBase {
|
|||||||
|
|
||||||
static guild(ctx: MethodContext<{ guildId: string }>) {
|
static guild(ctx: MethodContext<{ guildId: string }>) {
|
||||||
return {
|
return {
|
||||||
list: async () => {
|
list: () => ctx.client.webhooks.listFromChannel(ctx.guildId),
|
||||||
const webhooks = await ctx.client.proxy.guilds(ctx.guildId).webhooks.get();
|
|
||||||
return webhooks.map(webhook => new Webhook(ctx.client, webhook));
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -366,16 +362,8 @@ export class WebhookChannelMethods extends DiscordBase {
|
|||||||
|
|
||||||
static channel(ctx: MethodContext<{ channelId: string }>) {
|
static channel(ctx: MethodContext<{ channelId: string }>) {
|
||||||
return {
|
return {
|
||||||
list: async () => {
|
list: () => ctx.client.webhooks.listFromChannel(ctx.channelId),
|
||||||
const webhooks = await ctx.client.proxy.channels(ctx.channelId).webhooks.get();
|
create: async (body: RESTPostAPIChannelWebhookJSONBody) => ctx.client.webhooks.create(ctx.channelId, body),
|
||||||
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);
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user