micup.ts 1.0.0 → 1.1.1

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.
Files changed (94) hide show
  1. package/README.md +93 -38
  2. package/README.tr.md +137 -0
  3. package/dist/bot/client.d.ts +79 -0
  4. package/dist/bot/client.js +299 -0
  5. package/dist/events/background.d.ts +7 -0
  6. package/dist/events/background.js +23 -0
  7. package/dist/events/catalog.d.ts +243 -0
  8. package/dist/events/catalog.js +1 -0
  9. package/dist/events/guild-tag.d.ts +9 -0
  10. package/dist/events/guild-tag.js +38 -0
  11. package/dist/events/mux.d.ts +20 -5
  12. package/dist/events/names.d.ts +1 -0
  13. package/dist/events/names.js +71 -0
  14. package/dist/events/safe.d.ts +9 -0
  15. package/dist/events/safe.js +27 -0
  16. package/dist/gateway/compression.d.ts +9 -0
  17. package/dist/gateway/compression.js +119 -0
  18. package/dist/gateway/connection.js +42 -17
  19. package/dist/gateway/protocol.d.ts +4 -1
  20. package/dist/gateway/protocol.js +9 -3
  21. package/dist/gateway/subscription.d.ts +10 -0
  22. package/dist/gateway/subscription.js +26 -0
  23. package/dist/index.d.ts +48 -4
  24. package/dist/index.js +19 -3
  25. package/dist/model/components.d.ts +82 -0
  26. package/dist/model/components.js +74 -0
  27. package/dist/model/constants.d.ts +330 -0
  28. package/dist/model/constants.js +330 -0
  29. package/dist/model/embed.d.ts +59 -0
  30. package/dist/model/embed.js +40 -0
  31. package/dist/model/entities.d.ts +125 -0
  32. package/dist/model/entities.js +12 -0
  33. package/dist/model/format.d.ts +32 -0
  34. package/dist/model/format.js +61 -0
  35. package/dist/model/guild.d.ts +114 -1
  36. package/dist/model/helpers.d.ts +88 -0
  37. package/dist/model/helpers.js +185 -0
  38. package/dist/model/interaction.d.ts +1 -1
  39. package/dist/model/locale.d.ts +15 -0
  40. package/dist/model/locale.js +55 -0
  41. package/dist/model/media.d.ts +23 -0
  42. package/dist/model/media.js +65 -0
  43. package/dist/model/permissions.d.ts +5 -0
  44. package/dist/model/permissions.js +31 -0
  45. package/dist/rest/attachments.d.ts +26 -0
  46. package/dist/rest/attachments.js +82 -0
  47. package/dist/rest/channels.d.ts +87 -3
  48. package/dist/rest/channels.js +181 -2
  49. package/dist/rest/commands.d.ts +1 -0
  50. package/dist/rest/commands.js +17 -0
  51. package/dist/rest/discovery.d.ts +35 -0
  52. package/dist/rest/discovery.js +33 -0
  53. package/dist/rest/errors.d.ts +38 -0
  54. package/dist/rest/errors.js +46 -0
  55. package/dist/rest/expressions.d.ts +65 -0
  56. package/dist/rest/expressions.js +89 -0
  57. package/dist/rest/guilds.d.ts +102 -1
  58. package/dist/rest/guilds.js +127 -0
  59. package/dist/rest/identity.d.ts +1 -0
  60. package/dist/rest/identity.js +15 -0
  61. package/dist/rest/interactions.d.ts +1 -1
  62. package/dist/rest/messages.d.ts +54 -30
  63. package/dist/rest/messages.js +32 -12
  64. package/dist/rest/rooms.d.ts +142 -0
  65. package/dist/rest/rooms.js +133 -0
  66. package/dist/rest/sounds.d.ts +44 -0
  67. package/dist/rest/sounds.js +89 -0
  68. package/dist/rest/transport.d.ts +8 -2
  69. package/dist/rest/transport.js +38 -5
  70. package/dist/rest/users.d.ts +65 -0
  71. package/dist/rest/users.js +63 -0
  72. package/dist/rest/webhooks.d.ts +56 -0
  73. package/dist/rest/webhooks.js +94 -0
  74. package/dist/session/inventory.d.ts +22 -0
  75. package/dist/session/inventory.js +159 -0
  76. package/dist/session/session.d.ts +21 -2
  77. package/dist/session/session.js +61 -4
  78. package/dist/session/voice.d.ts +1 -0
  79. package/dist/session/voice.js +25 -17
  80. package/dist/shard/manager.d.ts +38 -1
  81. package/dist/shard/manager.js +87 -0
  82. package/dist/state/cache.d.ts +6 -1
  83. package/dist/state/cache.js +45 -1
  84. package/docs/README.md +13 -0
  85. package/docs/commands-and-interactions.md +120 -0
  86. package/docs/errors-and-limits.md +79 -0
  87. package/docs/gateway-and-sharding.md +102 -0
  88. package/docs/getting-started.md +79 -0
  89. package/docs/migrating.md +44 -0
  90. package/docs/rest-reference.md +101 -0
  91. package/docs/voice.md +95 -0
  92. package/package.json +25 -7
  93. package/dist/rest/client.d.ts +0 -48
  94. package/dist/rest/client.js +0 -151
@@ -0,0 +1,330 @@
1
+ export const AuditAction = {
2
+ GuildUpdate: 1,
3
+ ChannelCreate: 10,
4
+ ChannelUpdate: 11,
5
+ ChannelDelete: 12,
6
+ ChannelOverwriteCreate: 13,
7
+ ChannelOverwriteUpdate: 14,
8
+ ChannelOverwriteDelete: 15,
9
+ MemberKick: 20,
10
+ MemberPrune: 21,
11
+ MemberBanAdd: 22,
12
+ MemberBanRemove: 23,
13
+ MemberUpdate: 24,
14
+ MemberRoleUpdate: 25,
15
+ MemberMove: 26,
16
+ MemberDisconnect: 27,
17
+ BotAdd: 28,
18
+ RoleCreate: 30,
19
+ RoleUpdate: 31,
20
+ RoleDelete: 32,
21
+ InviteCreate: 40,
22
+ InviteUpdate: 41,
23
+ InviteDelete: 42,
24
+ WebhookCreate: 50,
25
+ WebhookUpdate: 51,
26
+ WebhookDelete: 52,
27
+ EmojiCreate: 60,
28
+ EmojiUpdate: 61,
29
+ EmojiDelete: 62,
30
+ MessageDelete: 72,
31
+ MessageBulkDelete: 73,
32
+ MessagePin: 74,
33
+ MessageUnpin: 75,
34
+ StickerCreate: 90,
35
+ StickerUpdate: 91,
36
+ StickerDelete: 92,
37
+ ThreadCreate: 110,
38
+ ThreadUpdate: 111,
39
+ ThreadDelete: 112,
40
+ };
41
+ export const ChannelType = {
42
+ GuildText: 0,
43
+ DM: 1,
44
+ GuildVoice: 2,
45
+ GroupDM: 3,
46
+ GuildCategory: 4,
47
+ GuildAnnouncement: 5,
48
+ AnnouncementThread: 10,
49
+ PublicThread: 11,
50
+ PrivateThread: 12,
51
+ GuildForum: 15,
52
+ GuildMedia: 16,
53
+ GuildLink: 998,
54
+ PersonalNotes: 999,
55
+ };
56
+ export const ChannelFlag = {
57
+ Pinned: 1 << 1,
58
+ RequireTag: 1 << 4,
59
+ HideMediaDownloadOptions: 1 << 15,
60
+ };
61
+ export const AutoArchiveDuration = {
62
+ Hour: 60,
63
+ Day: 1440,
64
+ ThreeDays: 4320,
65
+ Week: 10080,
66
+ };
67
+ export const ForumSortOrder = {
68
+ LatestActivity: 0,
69
+ CreationTime: 1,
70
+ };
71
+ export const ForumLayout = {
72
+ Default: 0,
73
+ List: 1,
74
+ Grid: 2,
75
+ };
76
+ export const ForumTagMatch = {
77
+ Some: 'match_some',
78
+ All: 'match_all',
79
+ };
80
+ export const ThreadMemberFlag = {
81
+ HasInteracted: 1 << 0,
82
+ AllMessages: 1 << 1,
83
+ OnlyMentions: 1 << 2,
84
+ NoMessages: 1 << 3,
85
+ };
86
+ export const VerificationLevel = {
87
+ None: 0,
88
+ Low: 1,
89
+ Medium: 2,
90
+ High: 3,
91
+ };
92
+ export const MfaLevel = {
93
+ None: 0,
94
+ Elevated: 1,
95
+ };
96
+ export const ExplicitContentFilter = {
97
+ Disabled: 0,
98
+ MembersWithoutRoles: 1,
99
+ AllMembers: 2,
100
+ };
101
+ export const DefaultMessageNotifications = {
102
+ AllMessages: 0,
103
+ OnlyMentions: 1,
104
+ };
105
+ export const SystemChannelFlag = {
106
+ SuppressJoinNotifications: 1 << 0,
107
+ };
108
+ export const GuildFeature = {
109
+ AnimatedBanner: 'ANIMATED_BANNER',
110
+ AnimatedIcon: 'ANIMATED_ICON',
111
+ Banner: 'BANNER',
112
+ CloneEmojiEnabled: 'CLONE_EMOJI_ENABLED',
113
+ CloneStickerEnabled: 'CLONE_STICKER_ENABLED',
114
+ DetachedBanner: 'DETACHED_BANNER',
115
+ Discoverable: 'DISCOVERABLE',
116
+ ExpressionPurgeAllowed: 'EXPRESSION_PURGE_ALLOWED',
117
+ HideOwnerCrown: 'HIDE_OWNER_CROWN',
118
+ InviteSplash: 'INVITE_SPLASH',
119
+ InvitesDisabled: 'INVITES_DISABLED',
120
+ Partnered: 'PARTNERED',
121
+ TextChannelFlexibleNames: 'TEXT_CHANNEL_FLEXIBLE_NAMES',
122
+ VanityURL: 'VANITY_URL',
123
+ Verified: 'VERIFIED',
124
+ VisitsEnabled: 'VISITS_ENABLED',
125
+ VoiceE2EE: 'VOICE_E2EE',
126
+ };
127
+ export const InviteType = {
128
+ Guild: 0,
129
+ GroupDM: 1,
130
+ };
131
+ export const MessageType = {
132
+ Default: 0,
133
+ RecipientAdd: 1,
134
+ RecipientRemove: 2,
135
+ Call: 3,
136
+ ChannelNameChange: 4,
137
+ ChannelIconChange: 5,
138
+ ChannelPinnedMessage: 6,
139
+ UserJoin: 7,
140
+ ChannelFollowAdd: 12,
141
+ ThreadCreated: 18,
142
+ Reply: 19,
143
+ ThreadStarterMessage: 21,
144
+ };
145
+ export const AttachmentFlag = {
146
+ Spoiler: 1 << 3,
147
+ ExplicitMedia: 1 << 4,
148
+ Animated: 1 << 5,
149
+ };
150
+ export const MessageReferenceType = {
151
+ Default: 0,
152
+ Forward: 1,
153
+ };
154
+ export const AllowedMentionType = {
155
+ Users: 'users',
156
+ Roles: 'roles',
157
+ Everyone: 'everyone',
158
+ };
159
+ export const SearchAuthorType = {
160
+ User: 'user',
161
+ Bot: 'bot',
162
+ Webhook: 'webhook',
163
+ };
164
+ export const SearchHas = {
165
+ Image: 'image',
166
+ Sound: 'sound',
167
+ Video: 'video',
168
+ File: 'file',
169
+ Sticker: 'sticker',
170
+ Embed: 'embed',
171
+ Link: 'link',
172
+ Snapshot: 'snapshot',
173
+ };
174
+ export const SearchSort = {
175
+ Timestamp: 'timestamp',
176
+ Relevance: 'relevance',
177
+ };
178
+ export const SortOrder = {
179
+ Ascending: 'asc',
180
+ Descending: 'desc',
181
+ };
182
+ export const EmbedType = {
183
+ Rich: 'rich',
184
+ };
185
+ export const ImageFormat = {
186
+ PNG: 'png',
187
+ JPEG: 'jpg',
188
+ WebP: 'webp',
189
+ GIF: 'gif',
190
+ AVIF: 'avif',
191
+ };
192
+ export const MemberProfileFlag = {
193
+ AvatarUnset: 1 << 0,
194
+ BannerUnset: 1 << 1,
195
+ };
196
+ export const MentionPreference = {
197
+ NoPreference: 0,
198
+ PreferMention: 1,
199
+ PreferNoMention: 2,
200
+ };
201
+ export const JoinSource = {
202
+ Creator: 0,
203
+ InstantInvite: 1,
204
+ VanityURL: 2,
205
+ BotInvite: 3,
206
+ AdminForceAdd: 4,
207
+ Discovery: 6,
208
+ };
209
+ export const UserFlag = {
210
+ Staff: 1 << 0,
211
+ Partner: 1 << 2,
212
+ BugHunter: 1 << 3,
213
+ FriendlyBot: 1 << 4,
214
+ FriendlyBotManualApproval: 1 << 5,
215
+ Spammer: 1 << 6,
216
+ ProfileHidden: 1 << 7,
217
+ };
218
+ export const WebhookType = {
219
+ Incoming: 1,
220
+ ChannelFollower: 2,
221
+ };
222
+ export const SelectDefaultType = {
223
+ User: 'user',
224
+ Role: 'role',
225
+ Channel: 'channel',
226
+ };
227
+ export const InteractionContextType = {
228
+ Guild: 0,
229
+ BotDM: 1,
230
+ PrivateChannel: 2,
231
+ };
232
+ export const Status = {
233
+ Online: 'online',
234
+ Idle: 'idle',
235
+ DND: 'dnd',
236
+ Invisible: 'invisible',
237
+ Offline: 'offline',
238
+ };
239
+ export const RelationshipType = {
240
+ Friend: 1,
241
+ Blocked: 2,
242
+ IncomingRequest: 3,
243
+ OutgoingRequest: 4,
244
+ };
245
+ export const GatewayFlag = {
246
+ DebounceMessageReactions: 1 << 1,
247
+ ChannelThreads: 1 << 2,
248
+ GuildVisits: 1 << 3,
249
+ };
250
+ export const GatewayCloseCode = {
251
+ UnknownError: 4000,
252
+ UnknownOpcode: 4001,
253
+ DecodeError: 4002,
254
+ NotAuthenticated: 4003,
255
+ AuthenticationFailed: 4004,
256
+ AlreadyAuthenticated: 4005,
257
+ InvalidSequence: 4007,
258
+ RateLimited: 4008,
259
+ SessionTimeout: 4009,
260
+ InvalidShard: 4010,
261
+ ShardingRequired: 4011,
262
+ InvalidAPIVersion: 4012,
263
+ };
264
+ export const VoiceRefusalCode = {
265
+ ChannelFull: 'VOICE_CHANNEL_FULL',
266
+ P2PConsentRequired: 'VOICE_P2P_CONSENT_REQUIRED',
267
+ P2PUnavailable: 'VOICE_P2P_UNAVAILABLE',
268
+ };
269
+ export const OverwriteType = {
270
+ Role: 0,
271
+ Member: 1,
272
+ };
273
+ export const Limits = {
274
+ GuildsPerShard: 2500,
275
+ AuditLogEntries: 100,
276
+ ChannelName: 100,
277
+ ChannelTopic: 1024,
278
+ ForumTopic: 4096,
279
+ SlowmodeSeconds: 21600,
280
+ ForumTags: 20,
281
+ AppliedTags: 5,
282
+ ForumTagName: 50,
283
+ ChannelPositions: 500,
284
+ CommandOptions: 25,
285
+ CommandChoices: 25,
286
+ CommandName: 32,
287
+ CommandDescription: 100,
288
+ ActionRows: 5,
289
+ ButtonsPerRow: 5,
290
+ CustomIDLength: 100,
291
+ ButtonLabelLength: 80,
292
+ EmbedTitle: 256,
293
+ EmbedDescription: 4096,
294
+ EmbedFields: 25,
295
+ EmbedFieldName: 256,
296
+ EmbedFieldValue: 1024,
297
+ EmbedFooter: 2048,
298
+ EmbedAuthor: 256,
299
+ EmbedURL: 2048,
300
+ InviteUses: 100,
301
+ InviteAge: 604800,
302
+ BulkExpressions: 50,
303
+ EmojiName: 32,
304
+ StickerName: 30,
305
+ Embeds: 10,
306
+ Attachments: 10,
307
+ BulkDelete: 100,
308
+ MessagesPerPage: 100,
309
+ StickersPerMessage: 3,
310
+ ReactionUsersPerPage: 100,
311
+ PinsPerPage: 50,
312
+ RefreshURLs: 50,
313
+ SearchHitsPerPage: 25,
314
+ SearchPage: 400,
315
+ ModalInputs: 5,
316
+ ModalTitle: 45,
317
+ TextInputLabel: 45,
318
+ TextInputLength: 4000,
319
+ TextInputPrompts: 100,
320
+ CustomStatusText: 128,
321
+ CustomStatusEmoji: 32,
322
+ RoleName: 100,
323
+ RoleColor: 0xFFFFFF,
324
+ SelectOptions: 25,
325
+ SelectPlaceholder: 150,
326
+ SelectOptionLabel: 100,
327
+ SelectOptionValue: 100,
328
+ SelectOptionDescription: 100,
329
+ WebhookName: 80,
330
+ };
@@ -0,0 +1,59 @@
1
+ export interface MicupEmbed {
2
+ title?: string;
3
+ description?: string;
4
+ url?: string;
5
+ color?: number;
6
+ timestamp?: string;
7
+ fields?: readonly {
8
+ name: string;
9
+ value: string;
10
+ inline?: boolean;
11
+ }[];
12
+ image?: EmbedMedia;
13
+ thumbnail?: EmbedMedia;
14
+ video?: EmbedMedia;
15
+ audio?: EmbedMedia;
16
+ footer?: {
17
+ text: string;
18
+ icon_url?: string;
19
+ proxy_icon_url?: string;
20
+ };
21
+ author?: {
22
+ name: string;
23
+ url?: string;
24
+ icon_url?: string;
25
+ proxy_icon_url?: string;
26
+ };
27
+ provider?: {
28
+ name: string;
29
+ url?: string;
30
+ };
31
+ type?: string;
32
+ nsfw?: boolean;
33
+ children?: readonly MicupEmbed[];
34
+ }
35
+ export interface EmbedMedia {
36
+ url: string;
37
+ proxy_url?: string;
38
+ width?: number;
39
+ height?: number;
40
+ duration?: number;
41
+ description?: string;
42
+ content_type?: string;
43
+ }
44
+ export declare function validateEmbed(embed: MicupEmbed): void;
45
+ export declare class EmbedBuilder {
46
+ #private;
47
+ title(value: string): this;
48
+ description(value: string): this;
49
+ url(value: string): this;
50
+ color(value: number): this;
51
+ timestamp(value: Date): this;
52
+ author(value: NonNullable<MicupEmbed['author']>): this;
53
+ footer(value: NonNullable<MicupEmbed['footer']>): this;
54
+ image(url: string): this;
55
+ thumbnail(url: string): this;
56
+ field(name: string, value: string, inline?: boolean): this;
57
+ build(): MicupEmbed;
58
+ }
59
+ export declare const attachmentURL: (filename: string) => string;
@@ -0,0 +1,40 @@
1
+ const length = (value) => value === undefined ? 0 : [...value].length;
2
+ export function validateEmbed(embed) {
3
+ if (length(embed.title) > 256 || length(embed.description) > 4096 || (embed.fields?.length ?? 0) > 25 ||
4
+ (embed.color !== undefined && (!Number.isInteger(embed.color) || embed.color < 0 || embed.color > 0xffffff))) {
5
+ throw new RangeError('Invalid Micup embed size or color');
6
+ }
7
+ for (const { name, value } of embed.fields ?? []) {
8
+ if (!name || length(name) > 256 || length(value) > 1024)
9
+ throw new RangeError('Invalid Micup embed field');
10
+ }
11
+ if (embed.author && (!embed.author.name || length(embed.author.name) > 256) ||
12
+ embed.footer && (!embed.footer.text || length(embed.footer.text) > 2048)) {
13
+ throw new RangeError('Invalid Micup embed author or footer');
14
+ }
15
+ for (const url of [embed.url, embed.image?.url, embed.thumbnail?.url]) {
16
+ if (url && Buffer.byteLength(url) > 2048)
17
+ throw new RangeError('Micup embed URL exceeds 2048 bytes');
18
+ }
19
+ }
20
+ export class EmbedBuilder {
21
+ #embed = {};
22
+ title(value) { this.#embed.title = value; return this; }
23
+ description(value) { this.#embed.description = value; return this; }
24
+ url(value) { this.#embed.url = value; return this; }
25
+ color(value) { this.#embed.color = value; return this; }
26
+ timestamp(value) { this.#embed.timestamp = value.toISOString(); return this; }
27
+ author(value) { this.#embed.author = { ...value }; return this; }
28
+ footer(value) { this.#embed.footer = { ...value }; return this; }
29
+ image(url) { this.#embed.image = { url }; return this; }
30
+ thumbnail(url) { this.#embed.thumbnail = { url }; return this; }
31
+ field(name, value, inline) {
32
+ this.#embed.fields = [...(this.#embed.fields ?? []), { name, value, inline }];
33
+ return this;
34
+ }
35
+ build() {
36
+ validateEmbed(this.#embed);
37
+ return structuredClone(this.#embed);
38
+ }
39
+ }
40
+ export const attachmentURL = (filename) => 'attachment://' + filename;
@@ -0,0 +1,125 @@
1
+ import type { MicupEmbed } from './embed.js';
2
+ import type { Emoji } from './format.js';
3
+ import type { MicupChannel } from './guild.js';
4
+ export declare const MessageFlag: {
5
+ readonly Crossposted: number;
6
+ readonly IsCrosspost: number;
7
+ readonly SuppressEmbeds: number;
8
+ readonly SourceMessageDeleted: number;
9
+ readonly HasThread: number;
10
+ readonly Ephemeral: number;
11
+ readonly FailedToMentionSomeRolesInThread: number;
12
+ readonly SuppressNotifications: number;
13
+ readonly VoiceMessage: number;
14
+ readonly IsComponentsV2: number;
15
+ };
16
+ export interface MicupUser {
17
+ id: string;
18
+ username: string;
19
+ bot?: boolean;
20
+ system?: boolean;
21
+ global_name?: string | null;
22
+ discriminator?: string;
23
+ avatar?: string | null;
24
+ avatar_color?: number | null;
25
+ banner?: string | null;
26
+ banner_color?: number | null;
27
+ accent_color?: number | null;
28
+ bio?: string | null;
29
+ pronouns?: string | null;
30
+ flags?: number;
31
+ mention_flags?: number;
32
+ tag_guild_id?: string | null;
33
+ }
34
+ export interface MessageAttachment {
35
+ id: string;
36
+ filename: string;
37
+ url: string;
38
+ proxy_url?: string;
39
+ title?: string;
40
+ description?: string | null;
41
+ size?: number;
42
+ content_type?: string;
43
+ width?: number;
44
+ height?: number;
45
+ flags?: number;
46
+ duration?: number;
47
+ expires_at?: string | null;
48
+ content_hash?: string;
49
+ placeholder?: string;
50
+ nsfw?: boolean;
51
+ waveform?: string;
52
+ expired?: boolean;
53
+ }
54
+ export interface MessageReactionCount {
55
+ count: number;
56
+ me?: boolean;
57
+ emoji: Emoji;
58
+ }
59
+ export interface StickerItem {
60
+ id: string;
61
+ name: string;
62
+ animated?: boolean;
63
+ }
64
+ export interface ChannelMention {
65
+ id: string;
66
+ name: string;
67
+ type: number;
68
+ }
69
+ export interface MessageSnapshotContent {
70
+ content: string;
71
+ timestamp?: string;
72
+ edited_timestamp?: string | null;
73
+ mentions?: readonly string[];
74
+ mention_roles?: readonly string[];
75
+ mention_channels?: readonly ChannelMention[];
76
+ embeds?: readonly MicupEmbed[];
77
+ attachments?: readonly MessageAttachment[];
78
+ stickers?: readonly StickerItem[];
79
+ type?: number;
80
+ flags?: number;
81
+ }
82
+ export interface MessageCall {
83
+ participants: readonly string[];
84
+ ended_timestamp?: string | null;
85
+ }
86
+ export interface MessageReference {
87
+ type?: number;
88
+ message_id: string;
89
+ channel_id?: string;
90
+ guild_id?: string;
91
+ attachment_ids?: readonly string[];
92
+ embed_indices?: readonly number[];
93
+ }
94
+ export interface MicupMessage {
95
+ id: string;
96
+ channel_id: string;
97
+ content: string;
98
+ author: MicupUser;
99
+ type?: number;
100
+ guild_id?: string;
101
+ flags?: number;
102
+ timestamp?: string;
103
+ edited_timestamp?: string | null;
104
+ pinned?: boolean;
105
+ tts?: boolean;
106
+ webhook_id?: string;
107
+ mention_everyone?: boolean;
108
+ mentions?: readonly MicupUser[];
109
+ mention_roles?: readonly string[];
110
+ mention_channels?: readonly ChannelMention[];
111
+ users?: readonly MicupUser[];
112
+ embeds?: readonly MicupEmbed[];
113
+ attachments?: readonly MessageAttachment[];
114
+ reactions?: readonly MessageReactionCount[];
115
+ components?: readonly unknown[];
116
+ stickers?: readonly StickerItem[];
117
+ nonce?: string | number;
118
+ message_reference?: MessageReference;
119
+ referenced_message?: MicupMessage | null;
120
+ message_snapshots?: readonly {
121
+ message: MessageSnapshotContent;
122
+ }[];
123
+ call?: MessageCall | null;
124
+ thread?: MicupChannel | null;
125
+ }
@@ -0,0 +1,12 @@
1
+ export const MessageFlag = {
2
+ Crossposted: 1 << 0,
3
+ IsCrosspost: 1 << 1,
4
+ SuppressEmbeds: 1 << 2,
5
+ SourceMessageDeleted: 1 << 3,
6
+ HasThread: 1 << 5,
7
+ Ephemeral: 1 << 6,
8
+ FailedToMentionSomeRolesInThread: 1 << 8,
9
+ SuppressNotifications: 1 << 12,
10
+ VoiceMessage: 1 << 13,
11
+ IsComponentsV2: 1 << 15,
12
+ };
@@ -0,0 +1,32 @@
1
+ import type { MicupUser } from './entities.js';
2
+ import type { MicupMember } from './guild.js';
3
+ export declare const TimestampStyle: {
4
+ readonly ShortTime: 't';
5
+ readonly LongTime: 'T';
6
+ readonly ShortDate: 'd';
7
+ readonly LongDate: 'D';
8
+ readonly ShortDateTime: 'f';
9
+ readonly LongDateTime: 'F';
10
+ readonly Relative: 'R';
11
+ };
12
+ export type TimestampStyle = typeof TimestampStyle[keyof typeof TimestampStyle];
13
+ export declare const snowflakeEpoch = 1420070400000;
14
+ export declare function parseSnowflake(id: string): bigint;
15
+ export declare function snowflakeTime(id: string): Date;
16
+ export declare function snowflakeAt(at: Date): string;
17
+ export declare function compareSnowflakes(a: string, b: string): number;
18
+ export declare const mentionUser: (id: string) => string;
19
+ export declare const mentionRole: (id: string) => string;
20
+ export declare const mentionChannel: (id: string) => string;
21
+ export declare function formatTimestamp(at: Date, style?: TimestampStyle): string;
22
+ export declare function escapeMarkdown(value: string): string;
23
+ export interface Emoji {
24
+ id?: string | null;
25
+ name: string;
26
+ animated?: boolean;
27
+ }
28
+ export declare function formatEmoji(emoji: Emoji): string;
29
+ export declare function reactionEmoji(emoji: Emoji): string;
30
+ export declare function userDisplayName(user: MicupUser): string;
31
+ export declare function memberDisplayName(member: MicupMember): string;
32
+ export declare function userTag(user: MicupUser): string;
@@ -0,0 +1,61 @@
1
+ export const TimestampStyle = {
2
+ ShortTime: 't', LongTime: 'T', ShortDate: 'd', LongDate: 'D', ShortDateTime: 'f', LongDateTime: 'F', Relative: 'R',
3
+ };
4
+ export const snowflakeEpoch = 1420070400000;
5
+ const maxSnowflake = (1n << 63n) - 1n;
6
+ export function parseSnowflake(id) {
7
+ if (typeof id !== 'string' || !/^(?:0|[1-9]\d{0,18})$/.test(id) || BigInt(id) > maxSnowflake) {
8
+ throw new TypeError('A snowflake must be a decimal string below 2^63');
9
+ }
10
+ return BigInt(id);
11
+ }
12
+ export function snowflakeTime(id) {
13
+ return new Date(Number(parseSnowflake(id) >> 22n) + snowflakeEpoch);
14
+ }
15
+ export function snowflakeAt(at) {
16
+ const timestamp = at.getTime();
17
+ if (!Number.isSafeInteger(timestamp))
18
+ throw new TypeError('A valid date is required');
19
+ const value = BigInt(Math.max(0, timestamp - snowflakeEpoch)) << 22n;
20
+ if (value > maxSnowflake)
21
+ throw new RangeError('Date exceeds the snowflake range');
22
+ return value.toString();
23
+ }
24
+ export function compareSnowflakes(a, b) {
25
+ if (a.length !== b.length)
26
+ return a.length < b.length ? -1 : 1;
27
+ if (a === b)
28
+ return 0;
29
+ return a < b ? -1 : 1;
30
+ }
31
+ export const mentionUser = (id) => '<@' + id + '>';
32
+ export const mentionRole = (id) => '<@&' + id + '>';
33
+ export const mentionChannel = (id) => '<#' + id + '>';
34
+ export function formatTimestamp(at, style) {
35
+ const seconds = Math.floor(at.getTime() / 1000);
36
+ if (!Number.isFinite(seconds))
37
+ throw new TypeError('A valid date is required');
38
+ return '<t:' + seconds + (style ? ':' + style : '') + '>';
39
+ }
40
+ const markdownCharacters = new Set(['\\', '*', '_', '~', String.fromCharCode(96), '|', '>', '<', '[', ']', '#']);
41
+ export function escapeMarkdown(value) {
42
+ return [...value].map((character) => markdownCharacters.has(character) ? '\\' + character : character).join('');
43
+ }
44
+ export function formatEmoji(emoji) {
45
+ if (!emoji.id)
46
+ return emoji.name;
47
+ return '<' + (emoji.animated ? 'a:' : ':') + emoji.name + ':' + emoji.id + '>';
48
+ }
49
+ export function reactionEmoji(emoji) {
50
+ return emoji.id ? emoji.name + ':' + emoji.id : emoji.name;
51
+ }
52
+ export function userDisplayName(user) {
53
+ return user.global_name || user.username;
54
+ }
55
+ export function memberDisplayName(member) {
56
+ return member.nick || (member.user ? userDisplayName(member.user) : '');
57
+ }
58
+ export function userTag(user) {
59
+ const discriminator = user.discriminator;
60
+ return !discriminator || discriminator === '0' || discriminator === '0000' ? user.username : user.username + '#' + discriminator;
61
+ }