baff.js 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/LICENSE +7 -0
- package/README.md +244 -3
- package/dist/cjs/builders/EmbedBuilder.d.ts +51 -0
- package/dist/cjs/builders/EmbedBuilder.js +150 -0
- package/dist/cjs/builders/SlashCommandBuilder.d.ts +69 -0
- package/dist/cjs/builders/SlashCommandBuilder.js +185 -0
- package/dist/cjs/builders/components/ActionRowBuilder.d.ts +14 -0
- package/dist/cjs/builders/components/ActionRowBuilder.js +45 -0
- package/dist/cjs/builders/components/ButtonBuilder.d.ts +19 -0
- package/dist/cjs/builders/components/ButtonBuilder.js +69 -0
- package/dist/cjs/builders/components/LayoutBuilders.d.ts +63 -0
- package/dist/cjs/builders/components/LayoutBuilders.js +179 -0
- package/dist/cjs/builders/components/ModalBuilder.d.ts +36 -0
- package/dist/cjs/builders/components/ModalBuilder.js +118 -0
- package/dist/cjs/builders/components/SelectMenuBuilder.d.ts +80 -0
- package/dist/cjs/builders/components/SelectMenuBuilder.js +192 -0
- package/dist/cjs/builders/components/shared.d.ts +16 -0
- package/dist/cjs/builders/components/shared.js +32 -0
- package/dist/cjs/builders/messagePayload.d.ts +35 -0
- package/dist/cjs/builders/messagePayload.js +88 -0
- package/dist/cjs/builders/validate.d.ts +12 -0
- package/dist/cjs/builders/validate.js +54 -0
- package/dist/cjs/client/Client.d.ts +63 -0
- package/dist/cjs/client/Client.js +152 -0
- package/dist/cjs/client/dispatch.d.ts +2 -0
- package/dist/cjs/client/dispatch.js +224 -0
- package/dist/cjs/client/events.d.ts +129 -0
- package/dist/cjs/client/events.js +2 -0
- package/dist/cjs/collectors/Collector.d.ts +37 -0
- package/dist/cjs/collectors/Collector.js +84 -0
- package/dist/cjs/collectors/InteractionCollector.d.ts +21 -0
- package/dist/cjs/collectors/InteractionCollector.js +44 -0
- package/dist/cjs/collectors/MessageCollector.d.ts +14 -0
- package/dist/cjs/collectors/MessageCollector.js +23 -0
- package/dist/cjs/errors/BaffError.d.ts +26 -0
- package/dist/cjs/errors/BaffError.js +39 -0
- package/dist/cjs/gateway/Gateway.d.ts +53 -0
- package/dist/cjs/gateway/Gateway.js +128 -0
- package/dist/cjs/http/handler.d.ts +11 -0
- package/dist/cjs/http/handler.js +72 -0
- package/dist/cjs/http/verify.d.ts +11 -0
- package/dist/cjs/http/verify.js +28 -0
- package/dist/cjs/index.d.ts +51 -0
- package/dist/cjs/index.js +185 -0
- package/dist/cjs/managers/CachedManager.d.ts +16 -0
- package/dist/cjs/managers/CachedManager.js +18 -0
- package/dist/cjs/managers/ChannelManager.d.ts +23 -0
- package/dist/cjs/managers/ChannelManager.js +85 -0
- package/dist/cjs/managers/CommandManager.d.ts +32 -0
- package/dist/cjs/managers/CommandManager.js +72 -0
- package/dist/cjs/managers/EventManager.d.ts +15 -0
- package/dist/cjs/managers/EventManager.js +36 -0
- package/dist/cjs/managers/ExpressionManagers.d.ts +36 -0
- package/dist/cjs/managers/ExpressionManagers.js +73 -0
- package/dist/cjs/managers/InviteManager.d.ts +17 -0
- package/dist/cjs/managers/InviteManager.js +26 -0
- package/dist/cjs/managers/MemberManager.d.ts +31 -0
- package/dist/cjs/managers/MemberManager.js +62 -0
- package/dist/cjs/managers/MessageManager.d.ts +32 -0
- package/dist/cjs/managers/MessageManager.js +79 -0
- package/dist/cjs/managers/RoleManager.d.ts +22 -0
- package/dist/cjs/managers/RoleManager.js +73 -0
- package/dist/cjs/managers/ServerChannelManager.d.ts +20 -0
- package/dist/cjs/managers/ServerChannelManager.js +30 -0
- package/dist/cjs/managers/ServerManager.d.ts +12 -0
- package/dist/cjs/managers/ServerManager.js +62 -0
- package/dist/cjs/managers/ThreadManager.d.ts +12 -0
- package/dist/cjs/managers/ThreadManager.js +20 -0
- package/dist/cjs/managers/UserManager.d.ts +11 -0
- package/dist/cjs/managers/UserManager.js +38 -0
- package/dist/cjs/managers/VoiceManager.d.ts +8 -0
- package/dist/cjs/managers/VoiceManager.js +17 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/rest/REST.d.ts +58 -0
- package/dist/cjs/rest/REST.js +193 -0
- package/dist/cjs/rest/Routes.d.ts +54 -0
- package/dist/cjs/rest/Routes.js +58 -0
- package/dist/cjs/rest/files.d.ts +19 -0
- package/dist/cjs/rest/files.js +37 -0
- package/dist/cjs/structures/Base.d.ts +13 -0
- package/dist/cjs/structures/Base.js +30 -0
- package/dist/cjs/structures/Message.d.ts +91 -0
- package/dist/cjs/structures/Message.js +200 -0
- package/dist/cjs/structures/Role.d.ts +34 -0
- package/dist/cjs/structures/Role.js +84 -0
- package/dist/cjs/structures/ScheduledEvent.d.ts +37 -0
- package/dist/cjs/structures/ScheduledEvent.js +73 -0
- package/dist/cjs/structures/Server.d.ts +68 -0
- package/dist/cjs/structures/Server.js +124 -0
- package/dist/cjs/structures/ServerAssets.d.ts +48 -0
- package/dist/cjs/structures/ServerAssets.js +104 -0
- package/dist/cjs/structures/ServerMember.d.ts +47 -0
- package/dist/cjs/structures/ServerMember.js +138 -0
- package/dist/cjs/structures/User.d.ts +35 -0
- package/dist/cjs/structures/User.js +87 -0
- package/dist/cjs/structures/Webhook.d.ts +30 -0
- package/dist/cjs/structures/Webhook.js +68 -0
- package/dist/cjs/structures/channels/BaseChannel.d.ts +49 -0
- package/dist/cjs/structures/channels/BaseChannel.js +81 -0
- package/dist/cjs/structures/channels/DMChannel.d.ts +9 -0
- package/dist/cjs/structures/channels/DMChannel.js +21 -0
- package/dist/cjs/structures/channels/ServerChannels.d.ts +57 -0
- package/dist/cjs/structures/channels/ServerChannels.js +138 -0
- package/dist/cjs/structures/channels/TextBasedChannel.d.ts +25 -0
- package/dist/cjs/structures/channels/TextBasedChannel.js +53 -0
- package/dist/cjs/structures/interactions/BaseInteraction.d.ts +74 -0
- package/dist/cjs/structures/interactions/BaseInteraction.js +221 -0
- package/dist/cjs/structures/interactions/CommandInteraction.d.ts +44 -0
- package/dist/cjs/structures/interactions/CommandInteraction.js +109 -0
- package/dist/cjs/structures/interactions/ComponentInteraction.d.ts +44 -0
- package/dist/cjs/structures/interactions/ComponentInteraction.js +64 -0
- package/dist/cjs/structures/interactions/ModalSubmitInteraction.d.ts +29 -0
- package/dist/cjs/structures/interactions/ModalSubmitInteraction.js +42 -0
- package/dist/cjs/structures/interactions/createInteraction.d.ts +4 -0
- package/dist/cjs/structures/interactions/createInteraction.js +34 -0
- package/dist/cjs/types.d.ts +369 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/util/Collection.d.ts +32 -0
- package/dist/cjs/util/Collection.js +145 -0
- package/dist/cjs/util/Permissions.d.ts +87 -0
- package/dist/cjs/util/Permissions.js +113 -0
- package/dist/cjs/util/Snowflake.d.ts +20 -0
- package/dist/cjs/util/Snowflake.js +40 -0
- package/dist/cjs/util/TypedEmitter.d.ts +17 -0
- package/dist/cjs/util/TypedEmitter.js +5 -0
- package/dist/cjs/util/constants.d.ts +78 -0
- package/dist/cjs/util/constants.js +81 -0
- package/dist/cjs/util/emoji.d.ts +8 -0
- package/dist/cjs/util/emoji.js +10 -0
- package/dist/cjs/util/formatters.d.ts +29 -0
- package/dist/cjs/util/formatters.js +55 -0
- package/dist/esm/builders/EmbedBuilder.d.ts +51 -0
- package/dist/esm/builders/EmbedBuilder.js +145 -0
- package/dist/esm/builders/SlashCommandBuilder.d.ts +69 -0
- package/dist/esm/builders/SlashCommandBuilder.js +170 -0
- package/dist/esm/builders/components/ActionRowBuilder.d.ts +14 -0
- package/dist/esm/builders/components/ActionRowBuilder.js +41 -0
- package/dist/esm/builders/components/ButtonBuilder.d.ts +19 -0
- package/dist/esm/builders/components/ButtonBuilder.js +65 -0
- package/dist/esm/builders/components/LayoutBuilders.d.ts +63 -0
- package/dist/esm/builders/components/LayoutBuilders.js +169 -0
- package/dist/esm/builders/components/ModalBuilder.d.ts +36 -0
- package/dist/esm/builders/components/ModalBuilder.js +113 -0
- package/dist/esm/builders/components/SelectMenuBuilder.d.ts +80 -0
- package/dist/esm/builders/components/SelectMenuBuilder.js +183 -0
- package/dist/esm/builders/components/shared.d.ts +16 -0
- package/dist/esm/builders/components/shared.js +26 -0
- package/dist/esm/builders/messagePayload.d.ts +35 -0
- package/dist/esm/builders/messagePayload.js +83 -0
- package/dist/esm/builders/validate.d.ts +12 -0
- package/dist/esm/builders/validate.js +46 -0
- package/dist/esm/client/Client.d.ts +63 -0
- package/dist/esm/client/Client.js +147 -0
- package/dist/esm/client/dispatch.d.ts +2 -0
- package/dist/esm/client/dispatch.js +221 -0
- package/dist/esm/client/events.d.ts +129 -0
- package/dist/esm/client/events.js +1 -0
- package/dist/esm/collectors/Collector.d.ts +37 -0
- package/dist/esm/collectors/Collector.js +78 -0
- package/dist/esm/collectors/InteractionCollector.d.ts +21 -0
- package/dist/esm/collectors/InteractionCollector.js +40 -0
- package/dist/esm/collectors/MessageCollector.d.ts +14 -0
- package/dist/esm/collectors/MessageCollector.js +19 -0
- package/dist/esm/errors/BaffError.d.ts +26 -0
- package/dist/esm/errors/BaffError.js +33 -0
- package/dist/esm/gateway/Gateway.d.ts +53 -0
- package/dist/esm/gateway/Gateway.js +124 -0
- package/dist/esm/http/handler.d.ts +11 -0
- package/dist/esm/http/handler.js +68 -0
- package/dist/esm/http/verify.d.ts +11 -0
- package/dist/esm/http/verify.js +22 -0
- package/dist/esm/index.d.ts +51 -0
- package/dist/esm/index.js +49 -0
- package/dist/esm/managers/CachedManager.d.ts +16 -0
- package/dist/esm/managers/CachedManager.js +14 -0
- package/dist/esm/managers/ChannelManager.d.ts +23 -0
- package/dist/esm/managers/ChannelManager.js +81 -0
- package/dist/esm/managers/CommandManager.d.ts +32 -0
- package/dist/esm/managers/CommandManager.js +67 -0
- package/dist/esm/managers/EventManager.d.ts +15 -0
- package/dist/esm/managers/EventManager.js +32 -0
- package/dist/esm/managers/ExpressionManagers.d.ts +36 -0
- package/dist/esm/managers/ExpressionManagers.js +68 -0
- package/dist/esm/managers/InviteManager.d.ts +17 -0
- package/dist/esm/managers/InviteManager.js +22 -0
- package/dist/esm/managers/MemberManager.d.ts +31 -0
- package/dist/esm/managers/MemberManager.js +58 -0
- package/dist/esm/managers/MessageManager.d.ts +32 -0
- package/dist/esm/managers/MessageManager.js +75 -0
- package/dist/esm/managers/RoleManager.d.ts +22 -0
- package/dist/esm/managers/RoleManager.js +69 -0
- package/dist/esm/managers/ServerChannelManager.d.ts +20 -0
- package/dist/esm/managers/ServerChannelManager.js +26 -0
- package/dist/esm/managers/ServerManager.d.ts +12 -0
- package/dist/esm/managers/ServerManager.js +58 -0
- package/dist/esm/managers/ThreadManager.d.ts +12 -0
- package/dist/esm/managers/ThreadManager.js +16 -0
- package/dist/esm/managers/UserManager.d.ts +11 -0
- package/dist/esm/managers/UserManager.js +34 -0
- package/dist/esm/managers/VoiceManager.d.ts +8 -0
- package/dist/esm/managers/VoiceManager.js +13 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/rest/REST.d.ts +58 -0
- package/dist/esm/rest/REST.js +188 -0
- package/dist/esm/rest/Routes.d.ts +54 -0
- package/dist/esm/rest/Routes.js +55 -0
- package/dist/esm/rest/files.d.ts +19 -0
- package/dist/esm/rest/files.js +31 -0
- package/dist/esm/structures/Base.d.ts +13 -0
- package/dist/esm/structures/Base.js +25 -0
- package/dist/esm/structures/Message.d.ts +91 -0
- package/dist/esm/structures/Message.js +194 -0
- package/dist/esm/structures/Role.d.ts +34 -0
- package/dist/esm/structures/Role.js +79 -0
- package/dist/esm/structures/ScheduledEvent.d.ts +37 -0
- package/dist/esm/structures/ScheduledEvent.js +68 -0
- package/dist/esm/structures/Server.d.ts +68 -0
- package/dist/esm/structures/Server.js +120 -0
- package/dist/esm/structures/ServerAssets.d.ts +48 -0
- package/dist/esm/structures/ServerAssets.js +98 -0
- package/dist/esm/structures/ServerMember.d.ts +47 -0
- package/dist/esm/structures/ServerMember.js +133 -0
- package/dist/esm/structures/User.d.ts +35 -0
- package/dist/esm/structures/User.js +82 -0
- package/dist/esm/structures/Webhook.d.ts +30 -0
- package/dist/esm/structures/Webhook.js +63 -0
- package/dist/esm/structures/channels/BaseChannel.d.ts +49 -0
- package/dist/esm/structures/channels/BaseChannel.js +77 -0
- package/dist/esm/structures/channels/DMChannel.d.ts +9 -0
- package/dist/esm/structures/channels/DMChannel.js +17 -0
- package/dist/esm/structures/channels/ServerChannels.d.ts +57 -0
- package/dist/esm/structures/channels/ServerChannels.js +129 -0
- package/dist/esm/structures/channels/TextBasedChannel.d.ts +25 -0
- package/dist/esm/structures/channels/TextBasedChannel.js +49 -0
- package/dist/esm/structures/interactions/BaseInteraction.d.ts +74 -0
- package/dist/esm/structures/interactions/BaseInteraction.js +217 -0
- package/dist/esm/structures/interactions/CommandInteraction.d.ts +44 -0
- package/dist/esm/structures/interactions/CommandInteraction.js +104 -0
- package/dist/esm/structures/interactions/ComponentInteraction.d.ts +44 -0
- package/dist/esm/structures/interactions/ComponentInteraction.js +53 -0
- package/dist/esm/structures/interactions/ModalSubmitInteraction.d.ts +29 -0
- package/dist/esm/structures/interactions/ModalSubmitInteraction.js +37 -0
- package/dist/esm/structures/interactions/createInteraction.d.ts +4 -0
- package/dist/esm/structures/interactions/createInteraction.js +31 -0
- package/dist/esm/types.d.ts +369 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/util/Collection.d.ts +32 -0
- package/dist/esm/util/Collection.js +141 -0
- package/dist/esm/util/Permissions.d.ts +87 -0
- package/dist/esm/util/Permissions.js +109 -0
- package/dist/esm/util/Snowflake.d.ts +20 -0
- package/dist/esm/util/Snowflake.js +37 -0
- package/dist/esm/util/TypedEmitter.d.ts +17 -0
- package/dist/esm/util/TypedEmitter.js +2 -0
- package/dist/esm/util/constants.d.ts +78 -0
- package/dist/esm/util/constants.js +78 -0
- package/dist/esm/util/emoji.d.ts +8 -0
- package/dist/esm/util/emoji.js +7 -0
- package/dist/esm/util/formatters.d.ts +29 -0
- package/dist/esm/util/formatters.js +34 -0
- package/package.json +58 -6
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Routes } from '../rest/Routes.js';
|
|
2
|
+
import { userMention } from '../util/formatters.js';
|
|
3
|
+
import { Identified } from './Base.js';
|
|
4
|
+
export class User extends Identified {
|
|
5
|
+
id;
|
|
6
|
+
username;
|
|
7
|
+
displayName;
|
|
8
|
+
avatarUrl = null;
|
|
9
|
+
bannerUrl = null;
|
|
10
|
+
tag = null;
|
|
11
|
+
clanTag = null;
|
|
12
|
+
status = null;
|
|
13
|
+
customStatus = null;
|
|
14
|
+
deleted = false;
|
|
15
|
+
constructor(client, data) {
|
|
16
|
+
super(client);
|
|
17
|
+
this.id = data.id;
|
|
18
|
+
this.username = data.username;
|
|
19
|
+
this.displayName = data.displayName || data.username;
|
|
20
|
+
this._patch(data);
|
|
21
|
+
}
|
|
22
|
+
_patch(data) {
|
|
23
|
+
if (data.username !== undefined)
|
|
24
|
+
this.username = data.username;
|
|
25
|
+
if (data.displayName !== undefined)
|
|
26
|
+
this.displayName = data.displayName || this.username;
|
|
27
|
+
if (data.avatarUrl !== undefined)
|
|
28
|
+
this.avatarUrl = data.avatarUrl;
|
|
29
|
+
if (data.bannerUrl !== undefined)
|
|
30
|
+
this.bannerUrl = data.bannerUrl;
|
|
31
|
+
if (data.tag !== undefined)
|
|
32
|
+
this.tag = data.tag;
|
|
33
|
+
if (data.clanTag !== undefined)
|
|
34
|
+
this.clanTag = data.clanTag;
|
|
35
|
+
if (data.status !== undefined)
|
|
36
|
+
this.status = data.status;
|
|
37
|
+
if (data.customStatus !== undefined)
|
|
38
|
+
this.customStatus = data.customStatus;
|
|
39
|
+
if (data.deleted !== undefined)
|
|
40
|
+
this.deleted = data.deleted;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
get bot() {
|
|
44
|
+
return this.tag === 'bot' || this.tag === 'verified_bot';
|
|
45
|
+
}
|
|
46
|
+
get system() {
|
|
47
|
+
return this.tag === 'system';
|
|
48
|
+
}
|
|
49
|
+
async createDM() {
|
|
50
|
+
const data = await this.client.rest.post(Routes.dms(), { body: { recipientId: this.id } });
|
|
51
|
+
return this.client.channels._addDM(data);
|
|
52
|
+
}
|
|
53
|
+
async send(options) {
|
|
54
|
+
return (await this.createDM()).send(options);
|
|
55
|
+
}
|
|
56
|
+
async fetchProfile(serverId) {
|
|
57
|
+
const profile = await this.client.rest.get(Routes.userProfile(this.id), { query: { serverId } });
|
|
58
|
+
this._patch(profile.user);
|
|
59
|
+
return profile;
|
|
60
|
+
}
|
|
61
|
+
toString() {
|
|
62
|
+
return userMention(this.id);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export class ClientUser extends User {
|
|
66
|
+
get bot() {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
async setPresence(presence) {
|
|
70
|
+
await this.client.rest.patch(Routes.presence(), { body: presence });
|
|
71
|
+
if (presence.status)
|
|
72
|
+
this.status = presence.status;
|
|
73
|
+
if (presence.customStatus !== undefined)
|
|
74
|
+
this.customStatus = presence.customStatus;
|
|
75
|
+
}
|
|
76
|
+
setStatus(status) {
|
|
77
|
+
return this.setPresence({ status });
|
|
78
|
+
}
|
|
79
|
+
setCustomStatus(customStatus) {
|
|
80
|
+
return this.setPresence({ customStatus });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Client } from '../client/Client.js';
|
|
2
|
+
import { type MessageOptions } from '../builders/messagePayload.js';
|
|
3
|
+
import { type RESTOptions } from '../rest/REST.js';
|
|
4
|
+
import type { APIWebhook } from '../types.js';
|
|
5
|
+
import { Identified } from './Base.js';
|
|
6
|
+
export type WebhookMessageOptions = Pick<MessageOptions, 'content' | 'embeds' | 'components' | 'flags'>;
|
|
7
|
+
export declare class Webhook extends Identified {
|
|
8
|
+
readonly channelId: string;
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly userId: string;
|
|
11
|
+
readonly token: string;
|
|
12
|
+
readonly path: string;
|
|
13
|
+
name: string;
|
|
14
|
+
constructor(client: Client, data: APIWebhook, channelId: string);
|
|
15
|
+
get url(): string;
|
|
16
|
+
send(options: string | WebhookMessageOptions): Promise<void>;
|
|
17
|
+
edit(name: string): Promise<Webhook>;
|
|
18
|
+
delete(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export declare class WebhookClient {
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly token: string;
|
|
23
|
+
private readonly rest;
|
|
24
|
+
constructor(target: string | {
|
|
25
|
+
id: string;
|
|
26
|
+
token: string;
|
|
27
|
+
api?: string;
|
|
28
|
+
}, options?: Omit<RESTOptions, 'token' | 'api'>);
|
|
29
|
+
send(options: string | WebhookMessageOptions): Promise<void>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { resolveMessage } from '../builders/messagePayload.js';
|
|
2
|
+
import { BaffError } from '../errors/BaffError.js';
|
|
3
|
+
import { REST } from '../rest/REST.js';
|
|
4
|
+
import { Routes } from '../rest/Routes.js';
|
|
5
|
+
import { Identified } from './Base.js';
|
|
6
|
+
export class Webhook extends Identified {
|
|
7
|
+
channelId;
|
|
8
|
+
id;
|
|
9
|
+
userId;
|
|
10
|
+
token;
|
|
11
|
+
path;
|
|
12
|
+
name;
|
|
13
|
+
constructor(client, data, channelId) {
|
|
14
|
+
super(client);
|
|
15
|
+
this.channelId = channelId;
|
|
16
|
+
this.id = data.id;
|
|
17
|
+
this.userId = data.userId;
|
|
18
|
+
this.name = data.name;
|
|
19
|
+
this.path = data.path;
|
|
20
|
+
this.token = data.path.split('/').filter(Boolean).at(-1) ?? '';
|
|
21
|
+
}
|
|
22
|
+
get url() {
|
|
23
|
+
return `${this.client.appUrl}${this.path}`;
|
|
24
|
+
}
|
|
25
|
+
async send(options) {
|
|
26
|
+
await send(this.client.rest, this.id, this.token, options);
|
|
27
|
+
}
|
|
28
|
+
async edit(name) {
|
|
29
|
+
await this.client.rest.patch(Routes.webhook(this.id), { body: { name } });
|
|
30
|
+
this.name = name;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
delete() {
|
|
34
|
+
return this.client.rest.delete(Routes.webhook(this.id));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function send(rest, id, token, options) {
|
|
38
|
+
const { body } = resolveMessage(options);
|
|
39
|
+
await rest.post(Routes.webhookExecute(id, token), { body, auth: false });
|
|
40
|
+
}
|
|
41
|
+
export class WebhookClient {
|
|
42
|
+
id;
|
|
43
|
+
token;
|
|
44
|
+
rest;
|
|
45
|
+
constructor(target, options = {}) {
|
|
46
|
+
let api;
|
|
47
|
+
if (typeof target === 'string') {
|
|
48
|
+
const match = /^(https?:\/\/.+?)\/api\/webhooks\/(\d+)\/([^/?#]+)/.exec(target);
|
|
49
|
+
if (!match)
|
|
50
|
+
throw new BaffError('INVALID_WEBHOOK_URL', 'Expected a URL like https://baff.gg/api/webhooks/<id>/<token>.');
|
|
51
|
+
api = `${match[1]}/api`;
|
|
52
|
+
this.id = match[2];
|
|
53
|
+
this.token = match[3];
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
({ id: this.id, token: this.token, api } = target);
|
|
57
|
+
}
|
|
58
|
+
this.rest = new REST({ ...options, api });
|
|
59
|
+
}
|
|
60
|
+
send(options) {
|
|
61
|
+
return send(this.rest, this.id, this.token, options);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Client } from '../../client/Client.js';
|
|
2
|
+
import type { APIChannel, ChannelKind } from '../../types.js';
|
|
3
|
+
import { Identified } from '../Base.js';
|
|
4
|
+
import type { Server } from '../Server.js';
|
|
5
|
+
import type { CategoryChannel, ForumChannel, ServerChannel, ThreadChannel, VoiceChannel } from './ServerChannels.js';
|
|
6
|
+
import type { DMChannel } from './DMChannel.js';
|
|
7
|
+
import type { TextBasedChannel } from './TextBasedChannel.js';
|
|
8
|
+
export interface ChannelEditData {
|
|
9
|
+
name?: string;
|
|
10
|
+
topic?: string | null;
|
|
11
|
+
slowmodeSecs?: number;
|
|
12
|
+
contentMode?: 'default' | 'spoiler' | 'age_restricted';
|
|
13
|
+
parentId?: string | null;
|
|
14
|
+
kind?: 'text' | 'announcement';
|
|
15
|
+
autoArchiveMinutes?: number;
|
|
16
|
+
archived?: boolean;
|
|
17
|
+
locked?: boolean;
|
|
18
|
+
availableTags?: {
|
|
19
|
+
id?: string;
|
|
20
|
+
name: string;
|
|
21
|
+
emoji?: string | null;
|
|
22
|
+
}[];
|
|
23
|
+
requireTag?: boolean;
|
|
24
|
+
defaultSortOrder?: 'activity' | 'created';
|
|
25
|
+
}
|
|
26
|
+
export declare class BaseChannel extends Identified {
|
|
27
|
+
readonly id: string;
|
|
28
|
+
kind: ChannelKind;
|
|
29
|
+
name: string | null;
|
|
30
|
+
serverId: string | null;
|
|
31
|
+
parentId: string | null;
|
|
32
|
+
position: number;
|
|
33
|
+
constructor(client: Client, data: APIChannel);
|
|
34
|
+
_patch(data: Partial<APIChannel>): this;
|
|
35
|
+
get server(): Server | null;
|
|
36
|
+
get parent(): CategoryChannel | null;
|
|
37
|
+
get url(): string;
|
|
38
|
+
isTextBased(): this is TextBasedChannel;
|
|
39
|
+
isVoiceBased(): this is VoiceChannel;
|
|
40
|
+
isThread(): this is ThreadChannel;
|
|
41
|
+
isDM(): this is DMChannel;
|
|
42
|
+
isForum(): this is ForumChannel;
|
|
43
|
+
isCategory(): this is CategoryChannel;
|
|
44
|
+
inServer(): this is ServerChannel;
|
|
45
|
+
edit(data: ChannelEditData): Promise<this>;
|
|
46
|
+
setName(name: string): Promise<this>;
|
|
47
|
+
delete(): Promise<void>;
|
|
48
|
+
toString(): string;
|
|
49
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Routes } from '../../rest/Routes.js';
|
|
2
|
+
import { channelMention } from '../../util/formatters.js';
|
|
3
|
+
import { Identified } from '../Base.js';
|
|
4
|
+
export class BaseChannel extends Identified {
|
|
5
|
+
id;
|
|
6
|
+
kind;
|
|
7
|
+
name = null;
|
|
8
|
+
serverId = null;
|
|
9
|
+
parentId = null;
|
|
10
|
+
position = 0;
|
|
11
|
+
constructor(client, data) {
|
|
12
|
+
super(client);
|
|
13
|
+
this.id = data.id;
|
|
14
|
+
this.kind = (data.kind ?? data.type ?? 'text');
|
|
15
|
+
}
|
|
16
|
+
_patch(data) {
|
|
17
|
+
if (data.kind ?? data.type)
|
|
18
|
+
this.kind = (data.kind ?? data.type);
|
|
19
|
+
if (data.name !== undefined)
|
|
20
|
+
this.name = data.name;
|
|
21
|
+
if (data.serverId !== undefined)
|
|
22
|
+
this.serverId = data.serverId;
|
|
23
|
+
if (data.parentId !== undefined)
|
|
24
|
+
this.parentId = data.parentId;
|
|
25
|
+
if (data.position !== undefined)
|
|
26
|
+
this.position = data.position;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
get server() {
|
|
30
|
+
return this.serverId ? (this.client.servers.cache.get(this.serverId) ?? null) : null;
|
|
31
|
+
}
|
|
32
|
+
get parent() {
|
|
33
|
+
const parent = this.parentId ? this.client.channels.cache.get(this.parentId) : undefined;
|
|
34
|
+
return parent?.isCategory() ? parent : null;
|
|
35
|
+
}
|
|
36
|
+
get url() {
|
|
37
|
+
const base = this.client.appUrl;
|
|
38
|
+
return this.serverId ? `${base}/channels/${this.serverId}/${this.id}` : `${base}/channels/@me/${this.id}`;
|
|
39
|
+
}
|
|
40
|
+
isTextBased() {
|
|
41
|
+
return ['text', 'announcement', 'stage', 'thread', 'dm', 'group_dm'].includes(this.kind);
|
|
42
|
+
}
|
|
43
|
+
isVoiceBased() {
|
|
44
|
+
return this.kind === 'voice';
|
|
45
|
+
}
|
|
46
|
+
isThread() {
|
|
47
|
+
return this.kind === 'thread';
|
|
48
|
+
}
|
|
49
|
+
isDM() {
|
|
50
|
+
return this.kind === 'dm' || this.kind === 'group_dm';
|
|
51
|
+
}
|
|
52
|
+
isForum() {
|
|
53
|
+
return this.kind === 'forum';
|
|
54
|
+
}
|
|
55
|
+
isCategory() {
|
|
56
|
+
return this.kind === 'category';
|
|
57
|
+
}
|
|
58
|
+
inServer() {
|
|
59
|
+
return this.serverId !== null;
|
|
60
|
+
}
|
|
61
|
+
async edit(data) {
|
|
62
|
+
const updated = await this.client.rest.patch(Routes.channel(this.id), { body: data });
|
|
63
|
+
if (updated && typeof updated === 'object' && updated.id === this.id)
|
|
64
|
+
this._patch(updated);
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
setName(name) {
|
|
68
|
+
return this.edit({ name });
|
|
69
|
+
}
|
|
70
|
+
async delete() {
|
|
71
|
+
await this.client.rest.delete(Routes.channel(this.id));
|
|
72
|
+
this.client.channels._remove(this.id);
|
|
73
|
+
}
|
|
74
|
+
toString() {
|
|
75
|
+
return channelMention(this.id);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { APIChannel } from '../../types.js';
|
|
2
|
+
import type { User } from '../User.js';
|
|
3
|
+
import { TextBasedChannel } from './TextBasedChannel.js';
|
|
4
|
+
export declare class DMChannel extends TextBasedChannel {
|
|
5
|
+
recipients: User[];
|
|
6
|
+
_patch(data: Partial<APIChannel>): this;
|
|
7
|
+
get recipient(): User | null;
|
|
8
|
+
get url(): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TextBasedChannel } from './TextBasedChannel.js';
|
|
2
|
+
export class DMChannel extends TextBasedChannel {
|
|
3
|
+
recipients = [];
|
|
4
|
+
_patch(data) {
|
|
5
|
+
super._patch(data);
|
|
6
|
+
const people = data.recipients ?? (data.recipient ? [data.recipient] : undefined);
|
|
7
|
+
if (people)
|
|
8
|
+
this.recipients = people.map((p) => this.client.users._add(p));
|
|
9
|
+
return this;
|
|
10
|
+
}
|
|
11
|
+
get recipient() {
|
|
12
|
+
return this.recipients[0] ?? null;
|
|
13
|
+
}
|
|
14
|
+
get url() {
|
|
15
|
+
return `${this.client.appUrl}/channels/@me/${this.id}`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Client } from '../../client/Client.js';
|
|
2
|
+
import { ThreadManager } from '../../managers/ThreadManager.js';
|
|
3
|
+
import type { MessageOptions } from '../../builders/messagePayload.js';
|
|
4
|
+
import type { APIChannel, APIVoiceJoin } from '../../types.js';
|
|
5
|
+
import { Collection } from '../../util/Collection.js';
|
|
6
|
+
import { BaseChannel } from './BaseChannel.js';
|
|
7
|
+
import { DMChannel } from './DMChannel.js';
|
|
8
|
+
import { TextBasedChannel } from './TextBasedChannel.js';
|
|
9
|
+
export declare class TextChannel extends TextBasedChannel {
|
|
10
|
+
contentMode: 'default' | 'spoiler' | 'age_restricted';
|
|
11
|
+
readonly threads: ThreadManager;
|
|
12
|
+
_patch(data: Partial<APIChannel>): this;
|
|
13
|
+
get isAnnouncement(): boolean;
|
|
14
|
+
get isStage(): boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare class ThreadChannel extends TextBasedChannel {
|
|
17
|
+
ownerId: string | null;
|
|
18
|
+
starterId: string | null;
|
|
19
|
+
archived: boolean;
|
|
20
|
+
locked: boolean;
|
|
21
|
+
autoArchiveMinutes: number | null;
|
|
22
|
+
messageCount: number;
|
|
23
|
+
_patch(data: Partial<APIChannel>): this;
|
|
24
|
+
setArchived(archived?: boolean): Promise<this>;
|
|
25
|
+
setLocked(locked?: boolean): Promise<this>;
|
|
26
|
+
}
|
|
27
|
+
export declare class VoiceChannel extends BaseChannel {
|
|
28
|
+
voiceStatus: string | null;
|
|
29
|
+
_patch(data: Partial<APIChannel>): this;
|
|
30
|
+
join(): Promise<APIVoiceJoin>;
|
|
31
|
+
setVoiceStatus(status: string | null): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
export declare class CategoryChannel extends BaseChannel {
|
|
34
|
+
get children(): Collection<string, ServerChannel>;
|
|
35
|
+
}
|
|
36
|
+
export declare class ForumChannel extends BaseChannel {
|
|
37
|
+
topic: string | null;
|
|
38
|
+
availableTags: NonNullable<APIChannel['availableTags']>;
|
|
39
|
+
requireTag: boolean;
|
|
40
|
+
_patch(data: Partial<APIChannel>): this;
|
|
41
|
+
createPost(options: {
|
|
42
|
+
name: string;
|
|
43
|
+
message: string | MessageOptions;
|
|
44
|
+
appliedTags?: string[];
|
|
45
|
+
autoArchiveMinutes?: number;
|
|
46
|
+
}): Promise<ThreadChannel>;
|
|
47
|
+
fetchPosts(options?: {
|
|
48
|
+
sort?: 'activity' | 'created';
|
|
49
|
+
q?: string;
|
|
50
|
+
tags?: string[];
|
|
51
|
+
offset?: number;
|
|
52
|
+
limit?: number;
|
|
53
|
+
}): Promise<ThreadChannel[]>;
|
|
54
|
+
}
|
|
55
|
+
export type ServerChannel = TextChannel | ThreadChannel | VoiceChannel | CategoryChannel | ForumChannel;
|
|
56
|
+
export type Channel = ServerChannel | DMChannel;
|
|
57
|
+
export declare function createChannel(client: Client, data: APIChannel): Channel;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { ThreadManager } from '../../managers/ThreadManager.js';
|
|
2
|
+
import { resolveMessage } from '../../builders/messagePayload.js';
|
|
3
|
+
import { Routes } from '../../rest/Routes.js';
|
|
4
|
+
import { BaffError } from '../../errors/BaffError.js';
|
|
5
|
+
import { BaseChannel } from './BaseChannel.js';
|
|
6
|
+
import { DMChannel } from './DMChannel.js';
|
|
7
|
+
import { TextBasedChannel } from './TextBasedChannel.js';
|
|
8
|
+
export class TextChannel extends TextBasedChannel {
|
|
9
|
+
contentMode = 'default';
|
|
10
|
+
threads = new ThreadManager(this);
|
|
11
|
+
_patch(data) {
|
|
12
|
+
super._patch(data);
|
|
13
|
+
if (data.contentMode !== undefined)
|
|
14
|
+
this.contentMode = data.contentMode;
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
get isAnnouncement() {
|
|
18
|
+
return this.kind === 'announcement';
|
|
19
|
+
}
|
|
20
|
+
get isStage() {
|
|
21
|
+
return this.kind === 'stage';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export class ThreadChannel extends TextBasedChannel {
|
|
25
|
+
ownerId = null;
|
|
26
|
+
starterId = null;
|
|
27
|
+
archived = false;
|
|
28
|
+
locked = false;
|
|
29
|
+
autoArchiveMinutes = null;
|
|
30
|
+
messageCount = 0;
|
|
31
|
+
_patch(data) {
|
|
32
|
+
super._patch(data);
|
|
33
|
+
if (data.threadOwnerId !== undefined)
|
|
34
|
+
this.ownerId = data.threadOwnerId;
|
|
35
|
+
if (data.threadStarterId !== undefined)
|
|
36
|
+
this.starterId = data.threadStarterId;
|
|
37
|
+
if (data.archived !== undefined)
|
|
38
|
+
this.archived = data.archived;
|
|
39
|
+
if (data.threadLocked !== undefined)
|
|
40
|
+
this.locked = data.threadLocked;
|
|
41
|
+
if (data.autoArchiveMinutes !== undefined)
|
|
42
|
+
this.autoArchiveMinutes = data.autoArchiveMinutes;
|
|
43
|
+
if (data.messageCount !== undefined)
|
|
44
|
+
this.messageCount = data.messageCount;
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
setArchived(archived = true) {
|
|
48
|
+
return this.edit({ archived });
|
|
49
|
+
}
|
|
50
|
+
setLocked(locked = true) {
|
|
51
|
+
return this.edit({ locked });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export class VoiceChannel extends BaseChannel {
|
|
55
|
+
voiceStatus = null;
|
|
56
|
+
_patch(data) {
|
|
57
|
+
super._patch(data);
|
|
58
|
+
if (data.voiceStatus !== undefined)
|
|
59
|
+
this.voiceStatus = data.voiceStatus;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
join() {
|
|
63
|
+
return this.client.voice.join(this.id);
|
|
64
|
+
}
|
|
65
|
+
async setVoiceStatus(status) {
|
|
66
|
+
await this.client.rest.put(Routes.channelVoiceStatus(this.id), { body: { status } });
|
|
67
|
+
this.voiceStatus = status;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export class CategoryChannel extends BaseChannel {
|
|
71
|
+
get children() {
|
|
72
|
+
return this.client.channels.cache.filter((c) => c.parentId === this.id && c.inServer());
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export class ForumChannel extends BaseChannel {
|
|
76
|
+
topic = null;
|
|
77
|
+
availableTags = [];
|
|
78
|
+
requireTag = false;
|
|
79
|
+
_patch(data) {
|
|
80
|
+
super._patch(data);
|
|
81
|
+
if (data.topic !== undefined)
|
|
82
|
+
this.topic = data.topic;
|
|
83
|
+
if (data.availableTags !== undefined)
|
|
84
|
+
this.availableTags = data.availableTags;
|
|
85
|
+
if (data.requireTag !== undefined)
|
|
86
|
+
this.requireTag = data.requireTag;
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
async createPost(options) {
|
|
90
|
+
const { body, files } = resolveMessage(options.message);
|
|
91
|
+
const payload = { name: options.name, appliedTags: options.appliedTags, autoArchiveMinutes: options.autoArchiveMinutes, message: body };
|
|
92
|
+
const data = await this.client.rest.post(Routes.channelThreads(this.id), { body: payload, files });
|
|
93
|
+
const post = createChannel(this.client, data);
|
|
94
|
+
if (!(post instanceof ThreadChannel))
|
|
95
|
+
throw new BaffError('UNEXPECTED_RESPONSE', 'The server did not answer with a post.');
|
|
96
|
+
this.client.channels._set(post);
|
|
97
|
+
return post;
|
|
98
|
+
}
|
|
99
|
+
async fetchPosts(options = {}) {
|
|
100
|
+
const res = await this.client.rest.get(Routes.channelPosts(this.id), { query: { ...options } });
|
|
101
|
+
return res.posts.map((p) => {
|
|
102
|
+
const post = createChannel(this.client, p.channel);
|
|
103
|
+
this.client.channels._set(post);
|
|
104
|
+
return post;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export function createChannel(client, data) {
|
|
109
|
+
const channel = construct(client, data);
|
|
110
|
+
channel._patch(data);
|
|
111
|
+
return channel;
|
|
112
|
+
}
|
|
113
|
+
function construct(client, data) {
|
|
114
|
+
switch (data.kind ?? data.type) {
|
|
115
|
+
case 'thread':
|
|
116
|
+
return new ThreadChannel(client, data);
|
|
117
|
+
case 'voice':
|
|
118
|
+
return new VoiceChannel(client, data);
|
|
119
|
+
case 'category':
|
|
120
|
+
return new CategoryChannel(client, data);
|
|
121
|
+
case 'forum':
|
|
122
|
+
return new ForumChannel(client, data);
|
|
123
|
+
case 'dm':
|
|
124
|
+
case 'group_dm':
|
|
125
|
+
return new DMChannel(client, data);
|
|
126
|
+
default:
|
|
127
|
+
return new TextChannel(client, data);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { MessageOptions } from '../../builders/messagePayload.js';
|
|
2
|
+
import { InteractionCollector, type InteractionCollectorOptions } from '../../collectors/InteractionCollector.js';
|
|
3
|
+
import { MessageCollector, type AwaitMessagesOptions, type MessageCollectorOptions } from '../../collectors/MessageCollector.js';
|
|
4
|
+
import { MessageManager } from '../../managers/MessageManager.js';
|
|
5
|
+
import type { APIChannel } from '../../types.js';
|
|
6
|
+
import type { Collection } from '../../util/Collection.js';
|
|
7
|
+
import type { MessageComponentInteraction } from '../interactions/ComponentInteraction.js';
|
|
8
|
+
import type { Message } from '../Message.js';
|
|
9
|
+
import { Webhook } from '../Webhook.js';
|
|
10
|
+
import { BaseChannel } from './BaseChannel.js';
|
|
11
|
+
export declare class TextBasedChannel extends BaseChannel {
|
|
12
|
+
readonly messages: MessageManager;
|
|
13
|
+
lastMessageId: string | null;
|
|
14
|
+
topic: string | null;
|
|
15
|
+
slowmodeSecs: number;
|
|
16
|
+
_patch(data: Partial<APIChannel>): this;
|
|
17
|
+
send(options: string | MessageOptions): Promise<Message>;
|
|
18
|
+
sendTyping(): Promise<void>;
|
|
19
|
+
createMessageCollector(options?: MessageCollectorOptions): MessageCollector;
|
|
20
|
+
awaitMessages(options?: AwaitMessagesOptions): Promise<Collection<string, Message>>;
|
|
21
|
+
createMessageComponentCollector(options?: InteractionCollectorOptions): InteractionCollector;
|
|
22
|
+
awaitMessageComponent(options?: InteractionCollectorOptions): Promise<MessageComponentInteraction>;
|
|
23
|
+
createWebhook(name: string): Promise<Webhook>;
|
|
24
|
+
fetchWebhooks(): Promise<Webhook[]>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { InteractionCollector } from '../../collectors/InteractionCollector.js';
|
|
2
|
+
import { MessageCollector } from '../../collectors/MessageCollector.js';
|
|
3
|
+
import { awaitCollector } from '../../collectors/Collector.js';
|
|
4
|
+
import { MessageManager } from '../../managers/MessageManager.js';
|
|
5
|
+
import { Routes } from '../../rest/Routes.js';
|
|
6
|
+
import { Webhook } from '../Webhook.js';
|
|
7
|
+
import { BaseChannel } from './BaseChannel.js';
|
|
8
|
+
export class TextBasedChannel extends BaseChannel {
|
|
9
|
+
messages = new MessageManager(this);
|
|
10
|
+
lastMessageId = null;
|
|
11
|
+
topic = null;
|
|
12
|
+
slowmodeSecs = 0;
|
|
13
|
+
_patch(data) {
|
|
14
|
+
super._patch(data);
|
|
15
|
+
if (data.lastMessageId !== undefined)
|
|
16
|
+
this.lastMessageId = data.lastMessageId;
|
|
17
|
+
if (data.topic !== undefined)
|
|
18
|
+
this.topic = data.topic;
|
|
19
|
+
if (data.slowmodeSecs !== undefined)
|
|
20
|
+
this.slowmodeSecs = data.slowmodeSecs;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
send(options) {
|
|
24
|
+
return this.messages.send(options);
|
|
25
|
+
}
|
|
26
|
+
async sendTyping() {
|
|
27
|
+
await this.client.rest.post(Routes.channelTyping(this.id));
|
|
28
|
+
}
|
|
29
|
+
createMessageCollector(options = {}) {
|
|
30
|
+
return new MessageCollector(this, options);
|
|
31
|
+
}
|
|
32
|
+
awaitMessages(options = {}) {
|
|
33
|
+
return awaitCollector(this.createMessageCollector(options), options.errors);
|
|
34
|
+
}
|
|
35
|
+
createMessageComponentCollector(options = {}) {
|
|
36
|
+
return new InteractionCollector(this.client, { ...options, channelId: this.id });
|
|
37
|
+
}
|
|
38
|
+
async awaitMessageComponent(options = {}) {
|
|
39
|
+
const collected = await awaitCollector(this.createMessageComponentCollector({ ...options, max: 1 }), ['time']);
|
|
40
|
+
return collected.first();
|
|
41
|
+
}
|
|
42
|
+
async createWebhook(name) {
|
|
43
|
+
return new Webhook(this.client, await this.client.rest.post(Routes.channelWebhooks(this.id), { body: { name } }), this.id);
|
|
44
|
+
}
|
|
45
|
+
async fetchWebhooks() {
|
|
46
|
+
const list = await this.client.rest.get(Routes.channelWebhooks(this.id));
|
|
47
|
+
return list.map((data) => new Webhook(this.client, data, this.id));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Client } from '../../client/Client.js';
|
|
2
|
+
import { type MessageOptions } from '../../builders/messagePayload.js';
|
|
3
|
+
import type { ModalBuilder } from '../../builders/components/ModalBuilder.js';
|
|
4
|
+
import type { APIInteraction } from '../../types.js';
|
|
5
|
+
import { PermissionsBitField } from '../../util/Permissions.js';
|
|
6
|
+
import { Identified } from '../Base.js';
|
|
7
|
+
import type { TextBasedChannel } from '../channels/TextBasedChannel.js';
|
|
8
|
+
import type { Message } from '../Message.js';
|
|
9
|
+
import type { Server } from '../Server.js';
|
|
10
|
+
import type { ServerMember } from '../ServerMember.js';
|
|
11
|
+
import type { User } from '../User.js';
|
|
12
|
+
import type { ButtonInteraction, ChannelSelectMenuInteraction, MentionableSelectMenuInteraction, MessageComponentInteraction, RoleSelectMenuInteraction, SelectMenuInteraction, StringSelectMenuInteraction, UserSelectMenuInteraction } from './ComponentInteraction.js';
|
|
13
|
+
import type { ChatInputCommandInteraction } from './CommandInteraction.js';
|
|
14
|
+
import type { ModalSubmitInteraction } from './ModalSubmitInteraction.js';
|
|
15
|
+
export interface InteractionReplyOptions extends MessageOptions {
|
|
16
|
+
ephemeral?: boolean;
|
|
17
|
+
}
|
|
18
|
+
type AnswerKind = 'message' | 'defer' | 'update' | 'deferUpdate' | 'modal';
|
|
19
|
+
export declare abstract class BaseInteraction extends Identified {
|
|
20
|
+
protected readonly raw: APIInteraction;
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly token: string;
|
|
23
|
+
readonly applicationId: string;
|
|
24
|
+
readonly channelId: string;
|
|
25
|
+
readonly serverId: string | null;
|
|
26
|
+
readonly user: User;
|
|
27
|
+
readonly roleIds: string[];
|
|
28
|
+
readonly memberPermissions: PermissionsBitField | null;
|
|
29
|
+
readonly appPermissions: PermissionsBitField | null;
|
|
30
|
+
replied: boolean;
|
|
31
|
+
deferred: boolean;
|
|
32
|
+
ephemeral: boolean;
|
|
33
|
+
protected answeredWith: AnswerKind | null;
|
|
34
|
+
protected replyMessage: Message | null;
|
|
35
|
+
private sink;
|
|
36
|
+
private viaResponse;
|
|
37
|
+
constructor(client: Client, raw: APIInteraction);
|
|
38
|
+
abstract readonly commandName: string;
|
|
39
|
+
get fullCommandName(): string;
|
|
40
|
+
get channel(): TextBasedChannel;
|
|
41
|
+
get server(): Server | null;
|
|
42
|
+
get member(): ServerMember | null;
|
|
43
|
+
get message(): Message | null;
|
|
44
|
+
get responded(): boolean;
|
|
45
|
+
_setSink(sink: ((body: Record<string, unknown>) => void) | null): void;
|
|
46
|
+
isChatInputCommand(): this is ChatInputCommandInteraction;
|
|
47
|
+
isMessageComponent(): this is MessageComponentInteraction;
|
|
48
|
+
isButton(): this is ButtonInteraction;
|
|
49
|
+
isAnySelectMenu(): this is SelectMenuInteraction;
|
|
50
|
+
isStringSelectMenu(): this is StringSelectMenuInteraction;
|
|
51
|
+
isUserSelectMenu(): this is UserSelectMenuInteraction;
|
|
52
|
+
isRoleSelectMenu(): this is RoleSelectMenuInteraction;
|
|
53
|
+
isMentionableSelectMenu(): this is MentionableSelectMenuInteraction;
|
|
54
|
+
isChannelSelectMenu(): this is ChannelSelectMenuInteraction;
|
|
55
|
+
isModalSubmit(): this is ModalSubmitInteraction;
|
|
56
|
+
isRepliable(): boolean;
|
|
57
|
+
reply(options: string | InteractionReplyOptions): Promise<void>;
|
|
58
|
+
deferReply(options?: {
|
|
59
|
+
ephemeral?: boolean;
|
|
60
|
+
}): Promise<void>;
|
|
61
|
+
update(options: string | MessageOptions): Promise<void>;
|
|
62
|
+
deferUpdate(): Promise<void>;
|
|
63
|
+
showModal(modal: ModalBuilder | ReturnType<ModalBuilder['toJSON']>): Promise<void>;
|
|
64
|
+
editReply(options: string | MessageOptions): Promise<Message | void>;
|
|
65
|
+
followUp(options: string | InteractionReplyOptions): Promise<void>;
|
|
66
|
+
deleteReply(): Promise<void>;
|
|
67
|
+
fetchReply(): Promise<Message>;
|
|
68
|
+
private afterAnswer;
|
|
69
|
+
private callback;
|
|
70
|
+
private mark;
|
|
71
|
+
private assertFresh;
|
|
72
|
+
private assertFromMessage;
|
|
73
|
+
}
|
|
74
|
+
export {};
|