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.
- package/README.md +93 -38
- package/README.tr.md +137 -0
- package/dist/bot/client.d.ts +79 -0
- package/dist/bot/client.js +299 -0
- package/dist/events/background.d.ts +7 -0
- package/dist/events/background.js +23 -0
- package/dist/events/catalog.d.ts +243 -0
- package/dist/events/catalog.js +1 -0
- package/dist/events/guild-tag.d.ts +9 -0
- package/dist/events/guild-tag.js +38 -0
- package/dist/events/mux.d.ts +20 -5
- package/dist/events/names.d.ts +1 -0
- package/dist/events/names.js +71 -0
- package/dist/events/safe.d.ts +9 -0
- package/dist/events/safe.js +27 -0
- package/dist/gateway/compression.d.ts +9 -0
- package/dist/gateway/compression.js +119 -0
- package/dist/gateway/connection.js +42 -17
- package/dist/gateway/protocol.d.ts +4 -1
- package/dist/gateway/protocol.js +9 -3
- package/dist/gateway/subscription.d.ts +10 -0
- package/dist/gateway/subscription.js +26 -0
- package/dist/index.d.ts +48 -4
- package/dist/index.js +19 -3
- package/dist/model/components.d.ts +82 -0
- package/dist/model/components.js +74 -0
- package/dist/model/constants.d.ts +330 -0
- package/dist/model/constants.js +330 -0
- package/dist/model/embed.d.ts +59 -0
- package/dist/model/embed.js +40 -0
- package/dist/model/entities.d.ts +125 -0
- package/dist/model/entities.js +12 -0
- package/dist/model/format.d.ts +32 -0
- package/dist/model/format.js +61 -0
- package/dist/model/guild.d.ts +114 -1
- package/dist/model/helpers.d.ts +88 -0
- package/dist/model/helpers.js +185 -0
- package/dist/model/interaction.d.ts +1 -1
- package/dist/model/locale.d.ts +15 -0
- package/dist/model/locale.js +55 -0
- package/dist/model/media.d.ts +23 -0
- package/dist/model/media.js +65 -0
- package/dist/model/permissions.d.ts +5 -0
- package/dist/model/permissions.js +31 -0
- package/dist/rest/attachments.d.ts +26 -0
- package/dist/rest/attachments.js +82 -0
- package/dist/rest/channels.d.ts +87 -3
- package/dist/rest/channels.js +181 -2
- package/dist/rest/commands.d.ts +1 -0
- package/dist/rest/commands.js +17 -0
- package/dist/rest/discovery.d.ts +35 -0
- package/dist/rest/discovery.js +33 -0
- package/dist/rest/errors.d.ts +38 -0
- package/dist/rest/errors.js +46 -0
- package/dist/rest/expressions.d.ts +65 -0
- package/dist/rest/expressions.js +89 -0
- package/dist/rest/guilds.d.ts +102 -1
- package/dist/rest/guilds.js +127 -0
- package/dist/rest/identity.d.ts +1 -0
- package/dist/rest/identity.js +15 -0
- package/dist/rest/interactions.d.ts +1 -1
- package/dist/rest/messages.d.ts +54 -30
- package/dist/rest/messages.js +32 -12
- package/dist/rest/rooms.d.ts +142 -0
- package/dist/rest/rooms.js +133 -0
- package/dist/rest/sounds.d.ts +44 -0
- package/dist/rest/sounds.js +89 -0
- package/dist/rest/transport.d.ts +8 -2
- package/dist/rest/transport.js +38 -5
- package/dist/rest/users.d.ts +65 -0
- package/dist/rest/users.js +63 -0
- package/dist/rest/webhooks.d.ts +56 -0
- package/dist/rest/webhooks.js +94 -0
- package/dist/session/inventory.d.ts +22 -0
- package/dist/session/inventory.js +159 -0
- package/dist/session/session.d.ts +21 -2
- package/dist/session/session.js +61 -4
- package/dist/session/voice.d.ts +1 -0
- package/dist/session/voice.js +25 -17
- package/dist/shard/manager.d.ts +38 -1
- package/dist/shard/manager.js +87 -0
- package/dist/state/cache.d.ts +6 -1
- package/dist/state/cache.js +45 -1
- package/docs/README.md +13 -0
- package/docs/commands-and-interactions.md +120 -0
- package/docs/errors-and-limits.md +79 -0
- package/docs/gateway-and-sharding.md +102 -0
- package/docs/getting-started.md +79 -0
- package/docs/migrating.md +44 -0
- package/docs/rest-reference.md +101 -0
- package/docs/voice.md +95 -0
- package/package.json +25 -7
- package/dist/rest/client.d.ts +0 -48
- package/dist/rest/client.js +0 -151
package/dist/model/guild.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MicupUser } from '
|
|
1
|
+
import type { MicupUser } from './entities.js';
|
|
2
2
|
export interface PermissionOverwrite {
|
|
3
3
|
id: string;
|
|
4
4
|
type: number;
|
|
@@ -10,7 +10,34 @@ export interface MicupRole {
|
|
|
10
10
|
name: string;
|
|
11
11
|
position: number;
|
|
12
12
|
permissions: string | number;
|
|
13
|
+
color?: number;
|
|
14
|
+
colors?: {
|
|
15
|
+
primary_color: number;
|
|
16
|
+
secondary_color: number | null;
|
|
17
|
+
tertiary_color: number | null;
|
|
18
|
+
};
|
|
19
|
+
hoist?: boolean;
|
|
20
|
+
hoist_position?: number | null;
|
|
21
|
+
mentionable?: boolean;
|
|
13
22
|
managed?: boolean;
|
|
23
|
+
icon?: string | null;
|
|
24
|
+
unicode_emoji?: string | null;
|
|
25
|
+
icon_emoji_id?: string | null;
|
|
26
|
+
}
|
|
27
|
+
export interface ForumTagRecord {
|
|
28
|
+
id: string;
|
|
29
|
+
name: string;
|
|
30
|
+
moderated?: boolean;
|
|
31
|
+
emoji_id?: string | null;
|
|
32
|
+
emoji_name?: string | null;
|
|
33
|
+
}
|
|
34
|
+
export interface ThreadMetadata {
|
|
35
|
+
archived: boolean;
|
|
36
|
+
auto_archive_duration: number;
|
|
37
|
+
archive_timestamp?: string;
|
|
38
|
+
locked?: boolean;
|
|
39
|
+
invitable?: boolean;
|
|
40
|
+
create_timestamp?: string;
|
|
14
41
|
}
|
|
15
42
|
export interface MicupChannel {
|
|
16
43
|
id: string;
|
|
@@ -19,13 +46,60 @@ export interface MicupChannel {
|
|
|
19
46
|
parent_id?: string | null;
|
|
20
47
|
name?: string;
|
|
21
48
|
topic?: string | null;
|
|
49
|
+
url?: string | null;
|
|
50
|
+
icon?: string | null;
|
|
51
|
+
owner_id?: string;
|
|
52
|
+
position?: number;
|
|
22
53
|
bitrate?: number;
|
|
54
|
+
user_limit?: number;
|
|
55
|
+
voice_connection_limit?: number;
|
|
56
|
+
rtc_region?: string | null;
|
|
57
|
+
rtc_p2p?: boolean;
|
|
58
|
+
nsfw?: boolean;
|
|
59
|
+
nsfw_override?: boolean | null;
|
|
60
|
+
content_warning_level?: number;
|
|
61
|
+
content_warning_text?: string | null;
|
|
62
|
+
rate_limit_per_user?: number;
|
|
63
|
+
last_message_id?: string | null;
|
|
64
|
+
last_pin_timestamp?: string | null;
|
|
23
65
|
permission_overwrites?: readonly PermissionOverwrite[];
|
|
66
|
+
permissions?: string | number;
|
|
67
|
+
recipients?: readonly MicupUser[];
|
|
68
|
+
nicks?: Readonly<Record<string, string>>;
|
|
69
|
+
flags?: number;
|
|
70
|
+
thread_metadata?: ThreadMetadata;
|
|
71
|
+
message_count?: number;
|
|
72
|
+
total_message_sent?: number;
|
|
73
|
+
member_count?: number;
|
|
74
|
+
applied_tags?: readonly string[];
|
|
75
|
+
member_ids_preview?: readonly string[];
|
|
76
|
+
member?: ThreadMember;
|
|
77
|
+
default_auto_archive_duration?: number;
|
|
78
|
+
default_thread_rate_limit_per_user?: number;
|
|
79
|
+
available_tags?: readonly ForumTagRecord[];
|
|
80
|
+
default_reaction_emoji?: {
|
|
81
|
+
emoji_id?: string | null;
|
|
82
|
+
emoji_name?: string | null;
|
|
83
|
+
} | null;
|
|
84
|
+
default_sort_order?: number | null;
|
|
85
|
+
default_forum_layout?: number;
|
|
86
|
+
default_tag_setting?: string;
|
|
24
87
|
}
|
|
25
88
|
export interface MicupMember {
|
|
26
89
|
user?: MicupUser;
|
|
27
90
|
roles: readonly string[];
|
|
28
91
|
nick?: string | null;
|
|
92
|
+
avatar?: string | null;
|
|
93
|
+
banner?: string | null;
|
|
94
|
+
accent_color?: number | null;
|
|
95
|
+
joined_at?: string;
|
|
96
|
+
mute?: boolean;
|
|
97
|
+
deaf?: boolean;
|
|
98
|
+
flags?: number;
|
|
99
|
+
profile_flags?: number;
|
|
100
|
+
mention_flags?: number;
|
|
101
|
+
communication_disabled_until?: string | null;
|
|
102
|
+
permissions?: string | number;
|
|
29
103
|
}
|
|
30
104
|
export interface MicupVoiceState {
|
|
31
105
|
guild_id?: string;
|
|
@@ -42,10 +116,42 @@ export interface MicupGuild {
|
|
|
42
116
|
owner_id?: string;
|
|
43
117
|
unavailable?: boolean;
|
|
44
118
|
features?: string[];
|
|
119
|
+
icon?: string | null;
|
|
120
|
+
banner?: string | null;
|
|
121
|
+
splash?: string | null;
|
|
122
|
+
afk_channel_id?: string | null;
|
|
123
|
+
afk_timeout?: number;
|
|
124
|
+
system_channel_id?: string | null;
|
|
125
|
+
system_channel_flags?: number;
|
|
126
|
+
rules_channel_id?: string | null;
|
|
127
|
+
vanity_url_code?: string | null;
|
|
128
|
+
verification_level?: number;
|
|
129
|
+
mfa_level?: number;
|
|
130
|
+
nsfw?: boolean;
|
|
131
|
+
nsfw_level?: number;
|
|
132
|
+
explicit_content_filter?: number;
|
|
133
|
+
default_message_notifications?: number;
|
|
134
|
+
premium_tier?: number;
|
|
135
|
+
premium_subscription_count?: number;
|
|
136
|
+
member_count?: number;
|
|
137
|
+
online_count?: number;
|
|
138
|
+
embed_splash?: string | null;
|
|
139
|
+
splash_card_alignment?: number;
|
|
140
|
+
badge_ids?: string[];
|
|
141
|
+
content_warning_level?: number;
|
|
142
|
+
content_warning_text?: string | null;
|
|
143
|
+
disabled_operations?: number;
|
|
144
|
+
message_history_cutoff?: string | null;
|
|
145
|
+
permissions?: string | number;
|
|
146
|
+
approximate_member_count?: number;
|
|
147
|
+
approximate_presence_count?: number;
|
|
148
|
+
guild_tag?: string | null;
|
|
149
|
+
guild_tag_badge?: string | null;
|
|
45
150
|
roles?: MicupRole[];
|
|
46
151
|
emojis?: {
|
|
47
152
|
id: string;
|
|
48
153
|
name?: string;
|
|
154
|
+
animated?: boolean;
|
|
49
155
|
}[];
|
|
50
156
|
stickers?: {
|
|
51
157
|
id: string;
|
|
@@ -67,3 +173,10 @@ export interface MicupMembersChunk {
|
|
|
67
173
|
not_found?: string[];
|
|
68
174
|
nonce?: string;
|
|
69
175
|
}
|
|
176
|
+
export interface ThreadMember {
|
|
177
|
+
id?: string;
|
|
178
|
+
user_id?: string;
|
|
179
|
+
join_timestamp?: string;
|
|
180
|
+
flags?: number;
|
|
181
|
+
member?: MicupMember;
|
|
182
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { type MicupMessage, type MicupUser } from './entities.js';
|
|
2
|
+
import type { Emoji } from './format.js';
|
|
3
|
+
import type { ActionRow, Button, SelectMenu, SelectOption, TextInput } from './components.js';
|
|
4
|
+
import type { MicupChannel, MicupGuild, MicupMember, MicupRole } from './guild.js';
|
|
5
|
+
import type { CommandData, CommandOptionValue, ComponentData, MicupInteraction, ModalData } from './interaction.js';
|
|
6
|
+
export declare function primaryButton(customId: string, label: string): Button;
|
|
7
|
+
export declare function secondaryButton(customId: string, label: string): Button;
|
|
8
|
+
export declare function successButton(customId: string, label: string): Button;
|
|
9
|
+
export declare function dangerButton(customId: string, label: string): Button;
|
|
10
|
+
export declare function linkButton(url: string, label: string): Button;
|
|
11
|
+
export declare function buttonWithEmoji(button: Button, emoji: Emoji): Button;
|
|
12
|
+
export declare function selectOption(label: string, value: string, extra?: Partial<Omit<SelectOption, 'label' | 'value'>>): SelectOption;
|
|
13
|
+
export declare function stringSelect(customId: string, ...options: SelectOption[]): SelectMenu;
|
|
14
|
+
export declare function userSelect(customId: string): SelectMenu;
|
|
15
|
+
export declare function roleSelect(customId: string): SelectMenu;
|
|
16
|
+
export declare function mentionableSelect(customId: string): SelectMenu;
|
|
17
|
+
export declare function channelSelect(customId: string, ...channelTypes: number[]): SelectMenu;
|
|
18
|
+
export declare const defaultUser: (id: string) => {
|
|
19
|
+
id: string;
|
|
20
|
+
type: 'user';
|
|
21
|
+
};
|
|
22
|
+
export declare const defaultRole: (id: string) => {
|
|
23
|
+
id: string;
|
|
24
|
+
type: 'role';
|
|
25
|
+
};
|
|
26
|
+
export declare const defaultChannel: (id: string) => {
|
|
27
|
+
id: string;
|
|
28
|
+
type: 'channel';
|
|
29
|
+
};
|
|
30
|
+
export declare function isSelectType(componentType: number): boolean;
|
|
31
|
+
export declare function shortInput(customId: string, label: string): TextInput;
|
|
32
|
+
export declare function paragraphInput(customId: string, label: string): TextInput;
|
|
33
|
+
export declare function disableButtons(rows: readonly ActionRow[]): ActionRow[];
|
|
34
|
+
export declare function buttonRow(...buttons: Button[]): ActionRow;
|
|
35
|
+
export declare function imageData(contentType: string, data: Uint8Array): string;
|
|
36
|
+
export declare const isCommandInteraction: (interaction: MicupInteraction) => boolean;
|
|
37
|
+
export declare const isAutocompleteInteraction: (interaction: MicupInteraction) => boolean;
|
|
38
|
+
export declare const isModalSubmitInteraction: (interaction: MicupInteraction) => boolean;
|
|
39
|
+
export declare const isButtonInteraction: (interaction: MicupInteraction) => boolean;
|
|
40
|
+
export declare const isSelectInteraction: (interaction: MicupInteraction) => boolean;
|
|
41
|
+
export declare function interactionCustomId(interaction: MicupInteraction): string | undefined;
|
|
42
|
+
export declare function interactionInvoker(interaction: MicupInteraction): MicupUser | undefined;
|
|
43
|
+
export declare function leafOptions(data: CommandData): readonly CommandOptionValue[];
|
|
44
|
+
export declare function commandOption(data: CommandData, name: string): CommandOptionValue | undefined;
|
|
45
|
+
export declare function focusedOption(data: CommandData): CommandOptionValue | undefined;
|
|
46
|
+
export declare function optionString(data: CommandData, name: string): string | undefined;
|
|
47
|
+
export declare function optionInteger(data: CommandData, name: string): number | undefined;
|
|
48
|
+
export declare function optionNumber(data: CommandData, name: string): number | undefined;
|
|
49
|
+
export declare function optionBoolean(data: CommandData, name: string): boolean | undefined;
|
|
50
|
+
export declare function optionUser(data: CommandData, name: string): MicupUser | undefined;
|
|
51
|
+
export declare function optionMember(data: CommandData, name: string): MicupMember | undefined;
|
|
52
|
+
export declare function optionRole(data: CommandData, name: string): MicupRole | undefined;
|
|
53
|
+
export declare function optionChannel(data: CommandData, name: string): MicupChannel | undefined;
|
|
54
|
+
export declare function optionAttachment(data: CommandData, name: string): {
|
|
55
|
+
id: string;
|
|
56
|
+
filename: string;
|
|
57
|
+
url: string;
|
|
58
|
+
} | undefined;
|
|
59
|
+
export declare function targetUser(data: CommandData): MicupUser | undefined;
|
|
60
|
+
export declare function targetMessage(data: CommandData): MicupMessage | undefined;
|
|
61
|
+
export declare function modalValue(data: ModalData, customId: string): string | undefined;
|
|
62
|
+
export declare function selectedUsers(data: ComponentData): MicupUser[];
|
|
63
|
+
export declare function selectedMembers(data: ComponentData): MicupMember[];
|
|
64
|
+
export declare function selectedRoles(data: ComponentData): MicupRole[];
|
|
65
|
+
export declare function selectedChannels(data: ComponentData): MicupChannel[];
|
|
66
|
+
export declare const isDMChannel: (channel: Pick<MicupChannel, 'type'>) => boolean;
|
|
67
|
+
export declare const isVoiceChannel: (channel: Pick<MicupChannel, 'type'>) => boolean;
|
|
68
|
+
export declare const isThreadChannel: (channel: Pick<MicupChannel, 'type'>) => boolean;
|
|
69
|
+
export declare const isForumChannel: (channel: Pick<MicupChannel, 'type'>) => boolean;
|
|
70
|
+
export declare const isReply: (message: Pick<MicupMessage, 'type'>) => boolean;
|
|
71
|
+
export declare const isForward: (message: {
|
|
72
|
+
message_reference?: {
|
|
73
|
+
type?: number;
|
|
74
|
+
};
|
|
75
|
+
}) => boolean;
|
|
76
|
+
export declare const isWebhookMessage: (message: {
|
|
77
|
+
webhook_id?: string;
|
|
78
|
+
}) => boolean;
|
|
79
|
+
export declare const hasMessageFlag: (message: Pick<MicupMessage, 'flags'>, flag: number) => boolean;
|
|
80
|
+
export declare const isSpoilerAttachment: (attachment: {
|
|
81
|
+
flags?: number;
|
|
82
|
+
}) => boolean;
|
|
83
|
+
export declare const messageCreatedAt: (message: Pick<MicupMessage, 'id'>) => Date;
|
|
84
|
+
export declare const isEphemeralMessage: (message: Pick<MicupMessage, 'flags'>) => boolean;
|
|
85
|
+
export declare function memberTimedOut(member: {
|
|
86
|
+
communication_disabled_until?: string | null;
|
|
87
|
+
}, now?: Date): boolean;
|
|
88
|
+
export declare function guildHasFeature(guild: Pick<MicupGuild, 'features'>, feature: string): boolean;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { MessageFlag } from './entities.js';
|
|
2
|
+
import { ButtonStyle, ComponentType, TextInputStyle, actionRow } from './components.js';
|
|
3
|
+
import { ChannelType, MessageReferenceType, MessageType } from './constants.js';
|
|
4
|
+
import { CommandOptionType, InteractionType } from './interaction.js';
|
|
5
|
+
import { snowflakeTime } from './format.js';
|
|
6
|
+
export function primaryButton(customId, label) {
|
|
7
|
+
return { type: 2, style: ButtonStyle.Primary, custom_id: customId, label };
|
|
8
|
+
}
|
|
9
|
+
export function secondaryButton(customId, label) {
|
|
10
|
+
return { type: 2, style: ButtonStyle.Secondary, custom_id: customId, label };
|
|
11
|
+
}
|
|
12
|
+
export function successButton(customId, label) {
|
|
13
|
+
return { type: 2, style: ButtonStyle.Success, custom_id: customId, label };
|
|
14
|
+
}
|
|
15
|
+
export function dangerButton(customId, label) {
|
|
16
|
+
return { type: 2, style: ButtonStyle.Danger, custom_id: customId, label };
|
|
17
|
+
}
|
|
18
|
+
export function linkButton(url, label) {
|
|
19
|
+
return { type: 2, style: ButtonStyle.Link, url, label };
|
|
20
|
+
}
|
|
21
|
+
export function buttonWithEmoji(button, emoji) {
|
|
22
|
+
return { ...button, emoji };
|
|
23
|
+
}
|
|
24
|
+
export function selectOption(label, value, extra = {}) {
|
|
25
|
+
return { label, value, ...extra };
|
|
26
|
+
}
|
|
27
|
+
export function stringSelect(customId, ...options) {
|
|
28
|
+
return { type: ComponentType.StringSelect, custom_id: customId, options };
|
|
29
|
+
}
|
|
30
|
+
export function userSelect(customId) {
|
|
31
|
+
return { type: ComponentType.UserSelect, custom_id: customId };
|
|
32
|
+
}
|
|
33
|
+
export function roleSelect(customId) {
|
|
34
|
+
return { type: ComponentType.RoleSelect, custom_id: customId };
|
|
35
|
+
}
|
|
36
|
+
export function mentionableSelect(customId) {
|
|
37
|
+
return { type: ComponentType.MentionableSelect, custom_id: customId };
|
|
38
|
+
}
|
|
39
|
+
export function channelSelect(customId, ...channelTypes) {
|
|
40
|
+
return { type: ComponentType.ChannelSelect, custom_id: customId, ...(channelTypes.length && { channel_types: channelTypes }) };
|
|
41
|
+
}
|
|
42
|
+
export const defaultUser = (id) => ({ id, type: 'user' });
|
|
43
|
+
export const defaultRole = (id) => ({ id, type: 'role' });
|
|
44
|
+
export const defaultChannel = (id) => ({ id, type: 'channel' });
|
|
45
|
+
export function isSelectType(componentType) {
|
|
46
|
+
return [ComponentType.StringSelect, ComponentType.UserSelect, ComponentType.RoleSelect, ComponentType.MentionableSelect, ComponentType.ChannelSelect]
|
|
47
|
+
.some((type) => type === componentType);
|
|
48
|
+
}
|
|
49
|
+
export function shortInput(customId, label) {
|
|
50
|
+
return { type: 4, style: TextInputStyle.Short, custom_id: customId, label };
|
|
51
|
+
}
|
|
52
|
+
export function paragraphInput(customId, label) {
|
|
53
|
+
return { type: 4, style: TextInputStyle.Paragraph, custom_id: customId, label };
|
|
54
|
+
}
|
|
55
|
+
export function disableButtons(rows) {
|
|
56
|
+
return rows.map((row) => ({
|
|
57
|
+
...row,
|
|
58
|
+
components: row.components.map((original) => {
|
|
59
|
+
const component = structuredClone(original);
|
|
60
|
+
if (component.type === 2 && component.style !== ButtonStyle.Link)
|
|
61
|
+
component.disabled = true;
|
|
62
|
+
return component;
|
|
63
|
+
}),
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
export function buttonRow(...buttons) {
|
|
67
|
+
return actionRow(...buttons);
|
|
68
|
+
}
|
|
69
|
+
export function imageData(contentType, data) {
|
|
70
|
+
if (!contentType || !data?.byteLength)
|
|
71
|
+
throw new TypeError('Image data needs a content type and bytes');
|
|
72
|
+
return 'data:' + contentType + ';base64,' + Buffer.from(data.buffer, data.byteOffset, data.byteLength).toString('base64');
|
|
73
|
+
}
|
|
74
|
+
export const isCommandInteraction = (interaction) => interaction.type === InteractionType.Command;
|
|
75
|
+
export const isAutocompleteInteraction = (interaction) => interaction.type === InteractionType.Autocomplete;
|
|
76
|
+
export const isModalSubmitInteraction = (interaction) => interaction.type === InteractionType.Modal;
|
|
77
|
+
export const isButtonInteraction = (interaction) => interaction.type === InteractionType.Component && interaction.data.component_type === ComponentType.Button;
|
|
78
|
+
export const isSelectInteraction = (interaction) => interaction.type === InteractionType.Component && isSelectType(interaction.data.component_type);
|
|
79
|
+
export function interactionCustomId(interaction) {
|
|
80
|
+
return interaction.type === InteractionType.Component || interaction.type === InteractionType.Modal ? interaction.data.custom_id : undefined;
|
|
81
|
+
}
|
|
82
|
+
export function interactionInvoker(interaction) {
|
|
83
|
+
return interaction.member?.user ?? interaction.user;
|
|
84
|
+
}
|
|
85
|
+
export function leafOptions(data) {
|
|
86
|
+
let options = data.options ?? [];
|
|
87
|
+
for (let depth = 0; depth < 2; depth++) {
|
|
88
|
+
const child = options.find((option) => option.type === CommandOptionType.Subcommand || option.type === CommandOptionType.SubcommandGroup);
|
|
89
|
+
if (!child)
|
|
90
|
+
break;
|
|
91
|
+
options = child.options ?? [];
|
|
92
|
+
}
|
|
93
|
+
return options;
|
|
94
|
+
}
|
|
95
|
+
export function commandOption(data, name) {
|
|
96
|
+
return leafOptions(data).find((option) => option.name === name);
|
|
97
|
+
}
|
|
98
|
+
export function focusedOption(data) {
|
|
99
|
+
return leafOptions(data).find((option) => option.focused);
|
|
100
|
+
}
|
|
101
|
+
export function optionString(data, name) {
|
|
102
|
+
const value = commandOption(data, name)?.value;
|
|
103
|
+
return typeof value === 'string' ? value : undefined;
|
|
104
|
+
}
|
|
105
|
+
export function optionInteger(data, name) {
|
|
106
|
+
const value = commandOption(data, name)?.value;
|
|
107
|
+
return typeof value === 'number' && Number.isInteger(value) ? value : undefined;
|
|
108
|
+
}
|
|
109
|
+
export function optionNumber(data, name) {
|
|
110
|
+
const value = commandOption(data, name)?.value;
|
|
111
|
+
return typeof value === 'number' ? value : undefined;
|
|
112
|
+
}
|
|
113
|
+
export function optionBoolean(data, name) {
|
|
114
|
+
const value = commandOption(data, name)?.value;
|
|
115
|
+
return typeof value === 'boolean' ? value : undefined;
|
|
116
|
+
}
|
|
117
|
+
function resolvedMember(resolved, id) {
|
|
118
|
+
const member = resolved?.members?.[id];
|
|
119
|
+
const user = resolved?.users?.[id];
|
|
120
|
+
return member ? { ...member, ...(user && { user }) } : undefined;
|
|
121
|
+
}
|
|
122
|
+
export function optionUser(data, name) {
|
|
123
|
+
const id = optionString(data, name);
|
|
124
|
+
return id === undefined ? undefined : data.resolved?.users?.[id];
|
|
125
|
+
}
|
|
126
|
+
export function optionMember(data, name) {
|
|
127
|
+
const id = optionString(data, name);
|
|
128
|
+
return id === undefined ? undefined : resolvedMember(data.resolved, id);
|
|
129
|
+
}
|
|
130
|
+
export function optionRole(data, name) {
|
|
131
|
+
const id = optionString(data, name);
|
|
132
|
+
return id === undefined ? undefined : data.resolved?.roles?.[id];
|
|
133
|
+
}
|
|
134
|
+
export function optionChannel(data, name) {
|
|
135
|
+
const id = optionString(data, name);
|
|
136
|
+
return id === undefined ? undefined : data.resolved?.channels?.[id];
|
|
137
|
+
}
|
|
138
|
+
export function optionAttachment(data, name) {
|
|
139
|
+
const id = optionString(data, name);
|
|
140
|
+
return id === undefined ? undefined : data.resolved?.attachments?.[id];
|
|
141
|
+
}
|
|
142
|
+
export function targetUser(data) {
|
|
143
|
+
return data.target_id === undefined ? undefined : data.resolved?.users?.[data.target_id];
|
|
144
|
+
}
|
|
145
|
+
export function targetMessage(data) {
|
|
146
|
+
return data.target_id === undefined ? undefined : data.resolved?.messages?.[data.target_id];
|
|
147
|
+
}
|
|
148
|
+
export function modalValue(data, customId) {
|
|
149
|
+
for (const row of data.components) {
|
|
150
|
+
for (const input of row.components ?? [])
|
|
151
|
+
if (input.custom_id === customId)
|
|
152
|
+
return input.value;
|
|
153
|
+
}
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
export function selectedUsers(data) {
|
|
157
|
+
return (data.values ?? []).flatMap((id) => data.resolved?.users?.[id] ?? []);
|
|
158
|
+
}
|
|
159
|
+
export function selectedMembers(data) {
|
|
160
|
+
return (data.values ?? []).flatMap((id) => resolvedMember(data.resolved, id) ?? []);
|
|
161
|
+
}
|
|
162
|
+
export function selectedRoles(data) {
|
|
163
|
+
return (data.values ?? []).flatMap((id) => data.resolved?.roles?.[id] ?? []);
|
|
164
|
+
}
|
|
165
|
+
export function selectedChannels(data) {
|
|
166
|
+
return (data.values ?? []).flatMap((id) => data.resolved?.channels?.[id] ?? []);
|
|
167
|
+
}
|
|
168
|
+
export const isDMChannel = (channel) => channel.type === ChannelType.DM || channel.type === ChannelType.GroupDM;
|
|
169
|
+
export const isVoiceChannel = (channel) => channel.type === ChannelType.GuildVoice;
|
|
170
|
+
export const isThreadChannel = (channel) => [ChannelType.AnnouncementThread, ChannelType.PublicThread, ChannelType.PrivateThread].some((type) => type === channel.type);
|
|
171
|
+
export const isForumChannel = (channel) => channel.type === ChannelType.GuildForum || channel.type === ChannelType.GuildMedia;
|
|
172
|
+
export const isReply = (message) => message.type === MessageType.Reply;
|
|
173
|
+
export const isForward = (message) => message.message_reference?.type === MessageReferenceType.Forward;
|
|
174
|
+
export const isWebhookMessage = (message) => Boolean(message.webhook_id);
|
|
175
|
+
export const hasMessageFlag = (message, flag) => ((message.flags ?? 0) & flag) === flag;
|
|
176
|
+
export const isSpoilerAttachment = (attachment) => ((attachment.flags ?? 0) & 8) !== 0;
|
|
177
|
+
export const messageCreatedAt = (message) => snowflakeTime(message.id);
|
|
178
|
+
export const isEphemeralMessage = (message) => hasMessageFlag(message, MessageFlag.Ephemeral);
|
|
179
|
+
export function memberTimedOut(member, now = new Date()) {
|
|
180
|
+
const until = member.communication_disabled_until;
|
|
181
|
+
return Boolean(until) && new Date(until).getTime() > now.getTime();
|
|
182
|
+
}
|
|
183
|
+
export function guildHasFeature(guild, feature) {
|
|
184
|
+
return guild.features?.includes(feature) ?? false;
|
|
185
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type LocalizedMessages = Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
2
|
+
export declare function normalizeLocale(locale: string): string;
|
|
3
|
+
export declare function isLocaleTag(locale: string): boolean;
|
|
4
|
+
export declare class MessageCatalog {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(fallback: string, messages: LocalizedMessages);
|
|
7
|
+
get fallback(): string;
|
|
8
|
+
get locales(): string[];
|
|
9
|
+
textIn(locale: string | undefined, key: string, ...values: unknown[]): string;
|
|
10
|
+
text(interaction: {
|
|
11
|
+
locale?: string;
|
|
12
|
+
guild_locale?: string;
|
|
13
|
+
}, key: string, ...values: unknown[]): string;
|
|
14
|
+
localizations(key: string): Record<string, string>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { format } from 'node:util';
|
|
2
|
+
export function normalizeLocale(locale) {
|
|
3
|
+
return locale.trim().replaceAll('_', '-').toLowerCase();
|
|
4
|
+
}
|
|
5
|
+
export function isLocaleTag(locale) {
|
|
6
|
+
return /^[a-z]{2,3}(?:-[a-z0-9]{2,8})*$/.test(normalizeLocale(locale));
|
|
7
|
+
}
|
|
8
|
+
export class MessageCatalog {
|
|
9
|
+
#byLocale = new Map();
|
|
10
|
+
#normalized = new Map();
|
|
11
|
+
#fallback;
|
|
12
|
+
constructor(fallback, messages) {
|
|
13
|
+
for (const [locale, translations] of Object.entries(messages)) {
|
|
14
|
+
const equivalent = normalizeLocale(locale);
|
|
15
|
+
if (!isLocaleTag(locale) || this.#normalized.has(equivalent))
|
|
16
|
+
throw new TypeError('Invalid or duplicate locale: ' + locale);
|
|
17
|
+
this.#normalized.set(equivalent, locale);
|
|
18
|
+
this.#byLocale.set(locale, new Map(Object.entries(translations)));
|
|
19
|
+
}
|
|
20
|
+
const baseLocale = this.#normalized.get(normalizeLocale(fallback));
|
|
21
|
+
const base = this.#byLocale.get(baseLocale ?? '');
|
|
22
|
+
if (!baseLocale || !base)
|
|
23
|
+
throw new TypeError('Fallback locale has no messages');
|
|
24
|
+
for (const translations of this.#byLocale.values()) {
|
|
25
|
+
for (const key of translations.keys()) {
|
|
26
|
+
if (!base.has(key))
|
|
27
|
+
throw new TypeError('Message does not appear in the fallback locale: ' + key);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
this.#fallback = baseLocale;
|
|
31
|
+
}
|
|
32
|
+
get fallback() {
|
|
33
|
+
return this.#fallback;
|
|
34
|
+
}
|
|
35
|
+
get locales() {
|
|
36
|
+
return [...this.#byLocale.keys()].sort();
|
|
37
|
+
}
|
|
38
|
+
textIn(locale, key, ...values) {
|
|
39
|
+
const normalized = normalizeLocale(locale ?? '');
|
|
40
|
+
const [language] = normalized.split('-');
|
|
41
|
+
const preferred = this.#normalized.get(normalized) ?? this.#normalized.get(language) ??
|
|
42
|
+
this.locales.find((locale) => normalizeLocale(locale).startsWith(language + '-'));
|
|
43
|
+
const text = this.#byLocale.get(preferred ?? '')?.get(key) ?? this.#byLocale.get(this.#fallback)?.get(key) ?? key;
|
|
44
|
+
return values.length ? format(text, ...values) : text;
|
|
45
|
+
}
|
|
46
|
+
text(interaction, key, ...values) {
|
|
47
|
+
return this.textIn(interaction.locale || interaction.guild_locale, key, ...values);
|
|
48
|
+
}
|
|
49
|
+
localizations(key) {
|
|
50
|
+
return Object.fromEntries(this.locales.flatMap((locale) => {
|
|
51
|
+
const text = this.#byLocale.get(locale)?.get(key);
|
|
52
|
+
return locale !== this.#fallback && text !== undefined ? [[locale, text]] : [];
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { MicupUser } from './entities.js';
|
|
2
|
+
import type { Emoji } from './format.js';
|
|
3
|
+
import type { MicupGuild, MicupMember, MicupRole } from './guild.js';
|
|
4
|
+
export interface MediaOptions {
|
|
5
|
+
format?: 'png' | 'jpg' | 'webp' | 'gif' | 'avif';
|
|
6
|
+
size?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function discoverPublicBase(value: unknown): string;
|
|
9
|
+
export declare class MicupMedia {
|
|
10
|
+
#private;
|
|
11
|
+
readonly base: string;
|
|
12
|
+
constructor(base: string);
|
|
13
|
+
userAvatar(user: MicupUser, options?: MediaOptions): string;
|
|
14
|
+
userBanner(user: MicupUser, options?: MediaOptions): string;
|
|
15
|
+
memberAvatar(guildId: string, member: MicupMember, options?: MediaOptions): string;
|
|
16
|
+
guildIcon(guild: MicupGuild, options?: MediaOptions): string;
|
|
17
|
+
guildBanner(guild: MicupGuild, options?: MediaOptions): string;
|
|
18
|
+
guildSplash(guild: MicupGuild, options?: MediaOptions): string;
|
|
19
|
+
roleIcon(role: MicupRole, options?: MediaOptions): string;
|
|
20
|
+
emojiImage(emoji: Emoji, options?: MediaOptions): string;
|
|
21
|
+
stickerImage(stickerId: string, options?: MediaOptions): string;
|
|
22
|
+
}
|
|
23
|
+
export declare function inviteURL(base: string, code: string): string;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export function discoverPublicBase(value) {
|
|
2
|
+
if (typeof value !== 'string' || !URL.canParse(value))
|
|
3
|
+
return '';
|
|
4
|
+
const url = new URL(value);
|
|
5
|
+
return ['http:', 'https:'].includes(url.protocol) && !url.username && !url.password && !url.search && !url.hash
|
|
6
|
+
? url.href.replace(/\/+$/, '') : '';
|
|
7
|
+
}
|
|
8
|
+
export class MicupMedia {
|
|
9
|
+
base;
|
|
10
|
+
constructor(base) {
|
|
11
|
+
this.base = discoverPublicBase(base);
|
|
12
|
+
}
|
|
13
|
+
userAvatar(user, options) {
|
|
14
|
+
return this.#image(['avatars', user.id], user.avatar, options);
|
|
15
|
+
}
|
|
16
|
+
userBanner(user, options) {
|
|
17
|
+
return this.#image(['banners', user.id], user.banner, options);
|
|
18
|
+
}
|
|
19
|
+
memberAvatar(guildId, member, options) {
|
|
20
|
+
if (!member.user)
|
|
21
|
+
return '';
|
|
22
|
+
return member.avatar ? this.#image(['guilds', guildId, 'users', member.user.id, 'avatars'], member.avatar, options)
|
|
23
|
+
: this.userAvatar(member.user, options);
|
|
24
|
+
}
|
|
25
|
+
guildIcon(guild, options) {
|
|
26
|
+
return this.#image(['icons', guild.id], guild.icon, options);
|
|
27
|
+
}
|
|
28
|
+
guildBanner(guild, options) {
|
|
29
|
+
return this.#image(['banners', guild.id], guild.banner, options);
|
|
30
|
+
}
|
|
31
|
+
guildSplash(guild, options) {
|
|
32
|
+
return this.#image(['splashes', guild.id], guild.splash, options);
|
|
33
|
+
}
|
|
34
|
+
roleIcon(role, options) {
|
|
35
|
+
return this.#image(['role-icons', role.id], role.icon, options);
|
|
36
|
+
}
|
|
37
|
+
emojiImage(emoji, options) {
|
|
38
|
+
return this.#image(['emojis'], emoji.id, options, emoji.animated);
|
|
39
|
+
}
|
|
40
|
+
stickerImage(stickerId, options) {
|
|
41
|
+
return this.#image(['stickers'], stickerId, options);
|
|
42
|
+
}
|
|
43
|
+
#image(parts, value, { format, size } = {}, animated = value?.startsWith('a_')) {
|
|
44
|
+
if (!this.base || !value)
|
|
45
|
+
return '';
|
|
46
|
+
if (format !== undefined && !['png', 'jpg', 'webp', 'gif', 'avif'].includes(format))
|
|
47
|
+
throw new TypeError('Invalid Micup image format');
|
|
48
|
+
const query = new URLSearchParams();
|
|
49
|
+
if (animated && (format === 'png' || format === 'jpg'))
|
|
50
|
+
query.set('animated', 'false');
|
|
51
|
+
if (size !== undefined) {
|
|
52
|
+
if (!Number.isSafeInteger(size) || size < 1)
|
|
53
|
+
throw new TypeError('A Micup image size must be a positive integer');
|
|
54
|
+
query.set('size', String(size));
|
|
55
|
+
}
|
|
56
|
+
const path = [...parts, value].map(encodeURIComponent).join('/');
|
|
57
|
+
return this.base + '/' + path + '.' + (format ?? 'webp') + (query.size ? '?' + query : '');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export function inviteURL(base, code) {
|
|
61
|
+
const prefix = discoverPublicBase(base);
|
|
62
|
+
if (!prefix || !code || code === '.' || code === '..')
|
|
63
|
+
throw new TypeError('An invite base URL and code are required');
|
|
64
|
+
return prefix + '/' + encodeURIComponent(code);
|
|
65
|
+
}
|
|
@@ -41,7 +41,12 @@ export declare const Permission: {
|
|
|
41
41
|
readonly BypassSlowmode: bigint;
|
|
42
42
|
readonly UpdateRTCRegion: bigint;
|
|
43
43
|
readonly ViewChannelMembers: bigint;
|
|
44
|
+
readonly ManageRoomStage: bigint;
|
|
44
45
|
readonly All: bigint;
|
|
45
46
|
};
|
|
46
47
|
export declare function hasPermissions(permissions: bigint, required: bigint): boolean;
|
|
48
|
+
export declare const ElevatedPermissions: bigint;
|
|
49
|
+
export declare function permissionNames(permissions: bigint): string[];
|
|
50
|
+
export declare function parsePermission(name: string): bigint | undefined;
|
|
51
|
+
export declare function missingPermissions(have: bigint, required: bigint): bigint;
|
|
47
52
|
export declare function computePermissions(guildId: string, ownerId: string | undefined, userId: string, roles: ReadonlyMap<string, MicupRole>, memberRoles: readonly string[], overwrites?: readonly PermissionOverwrite[]): bigint;
|
|
@@ -40,6 +40,7 @@ export const Permission = {
|
|
|
40
40
|
BypassSlowmode: 1n << 52n,
|
|
41
41
|
UpdateRTCRegion: 1n << 53n,
|
|
42
42
|
ViewChannelMembers: 1n << 54n,
|
|
43
|
+
ManageRoomStage: 1n << 62n,
|
|
43
44
|
All: (1n << 63n) - 1n,
|
|
44
45
|
};
|
|
45
46
|
function bits(value) {
|
|
@@ -52,6 +53,36 @@ function bits(value) {
|
|
|
52
53
|
export function hasPermissions(permissions, required) {
|
|
53
54
|
return (permissions & required) === required;
|
|
54
55
|
}
|
|
56
|
+
const permissionNameList = [
|
|
57
|
+
['CREATE_INSTANT_INVITE', Permission.CreateInstantInvite], ['KICK_MEMBERS', Permission.KickMembers], ['BAN_MEMBERS', Permission.BanMembers],
|
|
58
|
+
['ADMINISTRATOR', Permission.Administrator], ['MANAGE_CHANNELS', Permission.ManageChannels], ['MANAGE_GUILD', Permission.ManageGuild],
|
|
59
|
+
['ADD_REACTIONS', Permission.AddReactions], ['VIEW_AUDIT_LOG', Permission.ViewAuditLog], ['PRIORITY_SPEAKER', Permission.PrioritySpeaker],
|
|
60
|
+
['STREAM', Permission.Stream], ['VIEW_CHANNEL', Permission.ViewChannel], ['SEND_MESSAGES', Permission.SendMessages],
|
|
61
|
+
['SEND_TTS_MESSAGES', Permission.SendTTSMessages], ['MANAGE_MESSAGES', Permission.ManageMessages], ['EMBED_LINKS', Permission.EmbedLinks],
|
|
62
|
+
['ATTACH_FILES', Permission.AttachFiles], ['READ_MESSAGE_HISTORY', Permission.ReadMessageHistory], ['MENTION_EVERYONE', Permission.MentionEveryone],
|
|
63
|
+
['USE_EXTERNAL_EMOJIS', Permission.UseExternalEmojis], ['CONNECT', Permission.Connect], ['SPEAK', Permission.Speak],
|
|
64
|
+
['MUTE_MEMBERS', Permission.MuteMembers], ['DEAFEN_MEMBERS', Permission.DeafenMembers], ['MOVE_MEMBERS', Permission.MoveMembers],
|
|
65
|
+
['USE_VAD', Permission.UseVAD], ['CHANGE_NICKNAME', Permission.ChangeNickname], ['MANAGE_NICKNAMES', Permission.ManageNicknames],
|
|
66
|
+
['MANAGE_ROLES', Permission.ManageRoles], ['MANAGE_WEBHOOKS', Permission.ManageWebhooks], ['MANAGE_EXPRESSIONS', Permission.ManageExpressions],
|
|
67
|
+
['MANAGE_THREADS', Permission.ManageThreads], ['CREATE_PUBLIC_THREADS', Permission.CreatePublicThreads],
|
|
68
|
+
['CREATE_PRIVATE_THREADS', Permission.CreatePrivateThreads], ['USE_EXTERNAL_STICKERS', Permission.UseExternalStickers],
|
|
69
|
+
['SEND_MESSAGES_IN_THREADS', Permission.SendMessagesInThreads], ['MODERATE_MEMBERS', Permission.ModerateMembers],
|
|
70
|
+
['CREATE_EXPRESSIONS', Permission.CreateExpressions], ['PIN_MESSAGES', Permission.PinMessages], ['BYPASS_SLOWMODE', Permission.BypassSlowmode],
|
|
71
|
+
['UPDATE_RTC_REGION', Permission.UpdateRTCRegion], ['VIEW_CHANNEL_MEMBERS', Permission.ViewChannelMembers],
|
|
72
|
+
['MANAGE_ROOM_STAGE', Permission.ManageRoomStage],
|
|
73
|
+
];
|
|
74
|
+
export const ElevatedPermissions = Permission.KickMembers | Permission.BanMembers | Permission.Administrator | Permission.ManageChannels | Permission.ManageGuild |
|
|
75
|
+
Permission.ManageMessages | Permission.ManageRoles | Permission.ManageWebhooks | Permission.ModerateMembers | Permission.ManageThreads;
|
|
76
|
+
export function permissionNames(permissions) {
|
|
77
|
+
return permissionNameList.filter(([, bit]) => (permissions & bit) === bit).map(([name]) => name);
|
|
78
|
+
}
|
|
79
|
+
export function parsePermission(name) {
|
|
80
|
+
const wanted = name.trim().toUpperCase();
|
|
81
|
+
return permissionNameList.find(([known]) => known === wanted)?.[1];
|
|
82
|
+
}
|
|
83
|
+
export function missingPermissions(have, required) {
|
|
84
|
+
return (have & Permission.Administrator) === Permission.Administrator ? 0n : required & ~have;
|
|
85
|
+
}
|
|
55
86
|
export function computePermissions(guildId, ownerId, userId, roles, memberRoles, overwrites = []) {
|
|
56
87
|
if (userId && userId === ownerId)
|
|
57
88
|
return Permission.All;
|