@satorijs/adapter-discord 3.7.1 → 3.8.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.
@@ -1,4 +1,5 @@
1
1
  import { AllowedMentions, ApplicationCommand, Attachment, Channel, Component, ComponentType, Embed, GuildMember, integer, Message, Role, snowflake, User } from '.';
2
+ import * as Discord from '.';
2
3
  /** https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-structure */
3
4
  export interface Interaction {
4
5
  /** id of the interaction */
@@ -6,7 +7,7 @@ export interface Interaction {
6
7
  /** id of the application this interaction is for */
7
8
  application_id: snowflake;
8
9
  /** the type of interaction */
9
- type: InteractionType;
10
+ type: Interaction.Type;
10
11
  /** the command data payload */
11
12
  data?: InteractionData;
12
13
  /** the guild it was sent from */
@@ -43,12 +44,27 @@ export declare namespace InteractionData {
43
44
  /** converted users + roles + channels */
44
45
  resolved?: ResolvedData;
45
46
  /** the params + values from the user */
46
- options?: ApplicationCommandInteractionDataOption[];
47
+ options?: ApplicationCommand.Option[];
47
48
  /** the id of the guild the command is registered to */
48
49
  guild_id?: snowflake;
49
50
  /** id of the user or message targeted by a user or message command */
50
51
  target_id?: snowflake;
51
52
  }
53
+ namespace ApplicationCommand {
54
+ /** https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-application-command-interaction-data-option-structure */
55
+ interface Option {
56
+ /** the name of the parameter */
57
+ name: string;
58
+ /** value of application command option type */
59
+ type: Discord.ApplicationCommand.OptionType;
60
+ /** the value of the pair */
61
+ value?: any;
62
+ /** present if this option is a group or subcommand */
63
+ options?: Option[];
64
+ /** true if this option is the currently focused option for autocomplete */
65
+ focused?: boolean;
66
+ }
67
+ }
52
68
  /** https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-message-component-data-structure */
53
69
  interface MessageComponent {
54
70
  /** the custom_id of the component */
@@ -64,26 +80,15 @@ export declare namespace InteractionData {
64
80
  components: Component[];
65
81
  }
66
82
  }
67
- /** https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type */
68
- export declare enum InteractionType {
69
- PING = 1,
70
- APPLICATION_COMMAND = 2,
71
- MESSAGE_COMPONENT = 3,
72
- APPLICATION_COMMAND_AUTOCOMPLETE = 4,
73
- MODAL_SUBMIT = 5
74
- }
75
- /** https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-application-command-interaction-data-option-structure */
76
- export interface ApplicationCommandInteractionDataOption {
77
- /** the name of the parameter */
78
- name: string;
79
- /** value of application command option type */
80
- type: ApplicationCommand.OptionType;
81
- /** the value of the pair */
82
- value?: any;
83
- /** present if this option is a group or subcommand */
84
- options?: ApplicationCommandInteractionDataOption[];
85
- /** true if this option is the currently focused option for autocomplete */
86
- focused?: boolean;
83
+ export declare namespace Interaction {
84
+ /** https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type */
85
+ enum Type {
86
+ PING = 1,
87
+ APPLICATION_COMMAND = 2,
88
+ MESSAGE_COMPONENT = 3,
89
+ APPLICATION_COMMAND_AUTOCOMPLETE = 4,
90
+ MODAL_SUBMIT = 5
91
+ }
87
92
  }
88
93
  /** https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-resolved-data-structure */
89
94
  export interface ResolvedData {
@@ -105,7 +110,7 @@ export interface MessageInteraction {
105
110
  /** id of the interaction */
106
111
  id: snowflake;
107
112
  /** the type of interaction */
108
- type: InteractionType;
113
+ type: Interaction.Type;
109
114
  /** the name of the application command */
110
115
  name: string;
111
116
  /** the user who invoked the interaction */
@@ -113,71 +118,73 @@ export interface MessageInteraction {
113
118
  /** member who invoked the interaction in the guild */
114
119
  member?: Partial<GuildMember>;
115
120
  }
116
- /** https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-interaction-response-structure */
117
- export interface InteractionResponse {
118
- /** the type of response */
119
- type: InteractionCallbackType;
120
- /** an optional response message */
121
- data?: InteractionCallbackData;
122
- }
123
- /** https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-interaction-callback-type */
124
- export declare enum InteractionCallbackType {
125
- /** ACK a Ping */
126
- PONG = 1,
127
- /** respond to an interaction with a message */
128
- CHANNEL_MESSAGE_WITH_SOURCE = 4,
129
- /** ACK an interaction and edit a response later, the user sees a loading state */
130
- DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE = 5,
131
- /**
132
- * for components, ACK an interaction and edit the original message later; the user does not see a loading state
133
- * (only valid for [component-based](https://discord.com/developers/docs/interactions/message-components) interactions)
134
- */
135
- DEFERRED_UPDATE_MESSAGE = 6,
136
- /**
137
- * for components, edit the message the component was attached to
138
- * (only valid for [component-based](https://discord.com/developers/docs/interactions/message-components) interactions)
139
- */
140
- UPDATE_MESSAGE = 7,
141
- /** respond to an autocomplete interaction with suggested choices */
142
- APPLICATION_COMMAND_AUTOCOMPLETE_RESULT = 8,
143
- /**
144
- * respond to an interaction with a popup modal
145
- * (not available for `MODAL_SUBMIT` and `PING` interactions)
146
- */
147
- MODAL = 9
148
- }
149
- export type InteractionCallbackData = InteractionCallbackData.Messages | InteractionCallbackData.Autocomplete | InteractionCallbackData.Modal;
150
- export declare namespace InteractionCallbackData {
151
- /** https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-messages */
152
- interface Messages {
153
- /** is the response TTS */
154
- tts?: boolean;
155
- /** message content */
156
- content?: string;
157
- /** supports up to 10 embeds */
158
- embeds?: Embed[];
159
- /** allowed mentions object */
160
- allowed_mentions?: AllowedMentions;
161
- /** interaction callback data flags */
162
- flags?: integer;
163
- /** message components */
164
- components?: Component[];
165
- /** attachment objects with filename and description */
166
- attachments?: Partial<Attachment>[];
121
+ export declare namespace Interaction {
122
+ /** https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-interaction-response-structure */
123
+ interface Response {
124
+ /** the type of response */
125
+ type: CallbackType;
126
+ /** an optional response message */
127
+ data?: CallbackData;
167
128
  }
168
- /** https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-autocomplete */
169
- interface Autocomplete {
170
- /** autocomplete choices (max of 25 choices) */
171
- choices: ApplicationCommand.OptionChoice[];
129
+ /** https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-interaction-callback-type */
130
+ enum CallbackType {
131
+ /** ACK a Ping */
132
+ PONG = 1,
133
+ /** respond to an interaction with a message */
134
+ CHANNEL_MESSAGE_WITH_SOURCE = 4,
135
+ /** ACK an interaction and edit a response later, the user sees a loading state */
136
+ DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE = 5,
137
+ /**
138
+ * for components, ACK an interaction and edit the original message later; the user does not see a loading state
139
+ * (only valid for [component-based](https://discord.com/developers/docs/interactions/message-components) interactions)
140
+ */
141
+ DEFERRED_UPDATE_MESSAGE = 6,
142
+ /**
143
+ * for components, edit the message the component was attached to
144
+ * (only valid for [component-based](https://discord.com/developers/docs/interactions/message-components) interactions)
145
+ */
146
+ UPDATE_MESSAGE = 7,
147
+ /** respond to an autocomplete interaction with suggested choices */
148
+ APPLICATION_COMMAND_AUTOCOMPLETE_RESULT = 8,
149
+ /**
150
+ * respond to an interaction with a popup modal
151
+ * (not available for `MODAL_SUBMIT` and `PING` interactions)
152
+ */
153
+ MODAL = 9
172
154
  }
173
- /** https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-modal */
174
- interface Modal {
175
- /** a developer-defined identifier for the modal, max 100 characters */
176
- custom_id: string;
177
- /** the title of the popup modal, max 45 characters */
178
- title: string;
179
- /** between 1 and 5 (inclusive) components that make up the modal */
180
- components: Component[];
155
+ type CallbackData = CallbackData.Messages | CallbackData.Autocomplete | CallbackData.Modal;
156
+ namespace CallbackData {
157
+ /** https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-messages */
158
+ interface Messages {
159
+ /** is the response TTS */
160
+ tts?: boolean;
161
+ /** message content */
162
+ content?: string;
163
+ /** supports up to 10 embeds */
164
+ embeds?: Embed[];
165
+ /** allowed mentions object */
166
+ allowed_mentions?: AllowedMentions;
167
+ /** interaction callback data flags */
168
+ flags?: integer;
169
+ /** message components */
170
+ components?: Component[];
171
+ /** attachment objects with filename and description */
172
+ attachments?: Partial<Attachment>[];
173
+ }
174
+ /** https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-autocomplete */
175
+ interface Autocomplete {
176
+ /** autocomplete choices (max of 25 choices) */
177
+ choices: ApplicationCommand.OptionChoice[];
178
+ }
179
+ /** https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-modal */
180
+ interface Modal {
181
+ /** a developer-defined identifier for the modal, max 100 characters */
182
+ custom_id: string;
183
+ /** the title of the popup modal, max 45 characters */
184
+ title: string;
185
+ /** between 1 and 5 (inclusive) components that make up the modal */
186
+ components: Component[];
187
+ }
181
188
  }
182
189
  }
183
190
  export interface InteractionCreateEvent extends Interaction {
@@ -194,17 +201,17 @@ declare module './internal' {
194
201
  * Create a response to an Interaction from the gateway. Takes an interaction response. This endpoint also supports file attachments similar to the webhook endpoints. Refer to Uploading Files for details on uploading files and multipart/form-data requests.
195
202
  * @see https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response
196
203
  */
197
- createInteractionResponse(interaction_id: snowflake, token: string, params: InteractionResponse): Promise<void>;
204
+ createInteractionResponse(interaction_id: snowflake, token: string, params: Interaction.Response): Promise<void>;
198
205
  /**
199
206
  * Returns the initial Interaction response. Functions the same as Get Webhook Message.
200
207
  * @see https://discord.com/developers/docs/interactions/receiving-and-responding#get-original-interaction-response
201
208
  */
202
- getOriginalInteractionResponse(application_id: snowflake, token: string): Promise<InteractionResponse>;
209
+ getOriginalInteractionResponse(application_id: snowflake, token: string): Promise<Interaction.Response>;
203
210
  /**
204
211
  * Edits the initial Interaction response. Functions the same as Edit Webhook Message.
205
212
  * @see https://discord.com/developers/docs/interactions/receiving-and-responding#edit-original-interaction-response
206
213
  */
207
- editOriginalInteractionResponse(application_id: snowflake, token: string): Promise<InteractionResponse>;
214
+ editOriginalInteractionResponse(application_id: snowflake, token: string): Promise<Interaction.Response>;
208
215
  /**
209
216
  * Deletes the initial Interaction response. Returns 204 No Content on success.
210
217
  * @see https://discord.com/developers/docs/interactions/receiving-and-responding#delete-original-interaction-response
package/lib/utils.d.ts CHANGED
@@ -1,13 +1,16 @@
1
1
  import { Session, Universal } from '@satorijs/satori';
2
2
  import { DiscordBot } from './bot';
3
3
  import * as Discord from './types';
4
+ export * from './types';
4
5
  export declare const sanitize: (val: string) => string;
5
- export declare const adaptUser: (user: Discord.User) => Universal.User;
6
- export declare const adaptGuild: (data: Discord.Guild) => Universal.Guild;
7
- export declare const adaptChannel: (data: Discord.Channel) => Universal.Channel;
8
- export declare const adaptAuthor: (author: Discord.User) => Universal.Author;
6
+ export declare const decodeUser: (user: Discord.User) => Universal.User;
7
+ export declare const decodeGuild: (data: Discord.Guild) => Universal.Guild;
8
+ export declare const decodeChannel: (data: Discord.Channel) => Universal.Channel;
9
+ export declare const decodeAuthor: (author: Discord.User) => Universal.Author;
9
10
  export declare const decodeRole: (role: Discord.Role) => Universal.Role;
10
11
  export declare const encodeRole: (role: Partial<Universal.Role>) => Partial<Discord.Role>;
11
- export declare function adaptMessage(bot: DiscordBot, meta: Discord.Message, session?: Partial<Session>): Promise<Universal.Message>;
12
- export declare function prepareMessage(session: Partial<Session>, data: Partial<Discord.Message>): void;
13
- export declare function adaptSession(bot: DiscordBot, input: Discord.GatewayPayload): Promise<Session>;
12
+ export declare function decodeMessage(bot: DiscordBot, meta: Discord.Message, session?: Partial<Session>): Promise<Universal.Message>;
13
+ export declare function setupMessage(session: Partial<Session>, data: Partial<Discord.Message>): void;
14
+ export declare function adaptSession(bot: DiscordBot, input: Discord.Gateway.Payload): Promise<Session>;
15
+ export declare const encodeCommand: (cmd: Universal.Command) => Discord.ApplicationCommand.Params.Create;
16
+ export declare function encodeCommandOptions(cmd: Universal.Command): Discord.ApplicationCommand.Option[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@satorijs/adapter-discord",
3
3
  "description": "Discord Adapter for Satorijs",
4
- "version": "3.7.1",
4
+ "version": "3.8.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -29,7 +29,7 @@
29
29
  "satori"
30
30
  ],
31
31
  "peerDependencies": {
32
- "@satorijs/satori": "^2.4.0"
32
+ "@satorijs/satori": "^2.5.0"
33
33
  },
34
34
  "dependencies": {
35
35
  "form-data": "^4.0.0"