micup.ts 0.0.0-stage → 1.0.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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +79 -2
  3. package/dist/events/mux.d.ts +82 -0
  4. package/dist/events/mux.js +23 -0
  5. package/dist/events/router.d.ts +11 -0
  6. package/dist/events/router.js +54 -0
  7. package/dist/gateway/connection.d.ts +30 -0
  8. package/dist/gateway/connection.js +272 -0
  9. package/dist/gateway/protocol.d.ts +40 -0
  10. package/dist/gateway/protocol.js +59 -0
  11. package/dist/index.d.ts +29 -0
  12. package/dist/index.js +12 -0
  13. package/dist/model/guild.d.ts +69 -0
  14. package/dist/model/guild.js +1 -0
  15. package/dist/model/interaction.d.ts +137 -0
  16. package/dist/model/interaction.js +18 -0
  17. package/dist/model/permissions.d.ts +47 -0
  18. package/dist/model/permissions.js +81 -0
  19. package/dist/model/presence.d.ts +16 -0
  20. package/dist/model/presence.js +30 -0
  21. package/dist/rest/channels.d.ts +82 -0
  22. package/dist/rest/channels.js +68 -0
  23. package/dist/rest/client.d.ts +48 -0
  24. package/dist/rest/client.js +151 -0
  25. package/dist/rest/commands.d.ts +18 -0
  26. package/dist/rest/commands.js +94 -0
  27. package/dist/rest/errors.d.ts +24 -0
  28. package/dist/rest/errors.js +26 -0
  29. package/dist/rest/guilds.d.ts +76 -0
  30. package/dist/rest/guilds.js +90 -0
  31. package/dist/rest/interactions.d.ts +30 -0
  32. package/dist/rest/interactions.js +79 -0
  33. package/dist/rest/messages.d.ts +65 -0
  34. package/dist/rest/messages.js +38 -0
  35. package/dist/rest/transport.d.ts +16 -0
  36. package/dist/rest/transport.js +154 -0
  37. package/dist/session/requests.d.ts +39 -0
  38. package/dist/session/requests.js +144 -0
  39. package/dist/session/session.d.ts +63 -0
  40. package/dist/session/session.js +193 -0
  41. package/dist/session/voice.d.ts +41 -0
  42. package/dist/session/voice.js +168 -0
  43. package/dist/shard/manager.d.ts +20 -0
  44. package/dist/shard/manager.js +93 -0
  45. package/dist/state/cache.d.ts +15 -0
  46. package/dist/state/cache.js +257 -0
  47. package/package.json +39 -4
@@ -0,0 +1,29 @@
1
+ export { MicupClient } from './rest/client.js';
2
+ export type { MicupClientOptions, MicupMessage, MicupUser } from './rest/client.js';
3
+ export { EventMux } from './events/mux.js';
4
+ export type { MicupEvents } from './events/mux.js';
5
+ export { GatewayCloseError, GatewayOpcode } from './gateway/protocol.js';
6
+ export type { GatewayDispatch } from './gateway/protocol.js';
7
+ export { GatewaySession } from './session/session.js';
8
+ export type { GatewaySessionConfig, GatewaySessionOptions } from './session/session.js';
9
+ export { ShardManager, shardForGuild } from './shard/manager.js';
10
+ export type { ShardManagerOptions } from './shard/manager.js';
11
+ export { VoiceRefusedError } from './session/voice.js';
12
+ export type { VoiceJoinOptions, VoiceServerUpdate, VoiceSessionOptions } from './session/voice.js';
13
+ export { MicupAPIError } from './rest/errors.js';
14
+ export type { MicupFieldError } from './rest/errors.js';
15
+ export type { MicupRequestOptions, RestMethod, RestRequestOptions } from './rest/transport.js';
16
+ export type { AllowedMentions, ListMessageOptions, MessageInput, MicupEmbed, MicupFile } from './rest/messages.js';
17
+ export { GatewayState } from './state/cache.js';
18
+ export { Permission, computePermissions, hasPermissions } from './model/permissions.js';
19
+ export type { MicupChannel, MicupGuild, MicupGuildCreate, MicupMember, MicupMembersChunk, MicupRole, MicupVoiceState, PermissionOverwrite } from './model/guild.js';
20
+ export { InteractionRouter } from './events/router.js';
21
+ export { CommandOptionType, CommandType, InteractionType, commandPath } from './model/interaction.js';
22
+ export type { CommandChoice, CommandData, CommandDefinition, CommandOption, CommandOptionValue, ComponentData, MicupCommand, MicupInteraction, ModalData } from './model/interaction.js';
23
+ export type { CommandScope, MicupCommands } from './rest/commands.js';
24
+ export type { InteractionReplyOptions, MicupInteractions, MicupModal } from './rest/interactions.js';
25
+ export type { AuditOptions, GuildAuditLog, GuildBan, GuildBanInput, GuildMemberEdit, GuildMemberQuery, GuildRoleEdit, MicupGuilds } from './rest/guilds.js';
26
+ export type { ChannelEdit, MicupChannels, MicupInvite, ThreadList, ThreadStart } from './rest/channels.js';
27
+ export type { CustomStatus, Presence, PresenceStatus } from './model/presence.js';
28
+ export { GatewayRequestError } from './session/requests.js';
29
+ export type { ChannelMemberCount, GuildCount, GuildMembersRequest } from './session/requests.js';
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ export { MicupClient } from './rest/client.js';
2
+ export { EventMux } from './events/mux.js';
3
+ export { GatewayCloseError, GatewayOpcode } from './gateway/protocol.js';
4
+ export { GatewaySession } from './session/session.js';
5
+ export { ShardManager, shardForGuild } from './shard/manager.js';
6
+ export { VoiceRefusedError } from './session/voice.js';
7
+ export { MicupAPIError } from './rest/errors.js';
8
+ export { GatewayState } from './state/cache.js';
9
+ export { Permission, computePermissions, hasPermissions } from './model/permissions.js';
10
+ export { InteractionRouter } from './events/router.js';
11
+ export { CommandOptionType, CommandType, InteractionType, commandPath } from './model/interaction.js';
12
+ export { GatewayRequestError } from './session/requests.js';
@@ -0,0 +1,69 @@
1
+ import type { MicupUser } from '../rest/client.js';
2
+ export interface PermissionOverwrite {
3
+ id: string;
4
+ type: number;
5
+ allow: string | number;
6
+ deny: string | number;
7
+ }
8
+ export interface MicupRole {
9
+ id: string;
10
+ name: string;
11
+ position: number;
12
+ permissions: string | number;
13
+ managed?: boolean;
14
+ }
15
+ export interface MicupChannel {
16
+ id: string;
17
+ guild_id?: string;
18
+ type?: number;
19
+ parent_id?: string | null;
20
+ name?: string;
21
+ topic?: string | null;
22
+ bitrate?: number;
23
+ permission_overwrites?: readonly PermissionOverwrite[];
24
+ }
25
+ export interface MicupMember {
26
+ user?: MicupUser;
27
+ roles: readonly string[];
28
+ nick?: string | null;
29
+ }
30
+ export interface MicupVoiceState {
31
+ guild_id?: string;
32
+ user_id: string;
33
+ channel_id: string | null;
34
+ connection_id?: string;
35
+ member?: MicupMember;
36
+ self_mute?: boolean;
37
+ self_deaf?: boolean;
38
+ }
39
+ export interface MicupGuild {
40
+ id: string;
41
+ name?: string;
42
+ owner_id?: string;
43
+ unavailable?: boolean;
44
+ features?: string[];
45
+ roles?: MicupRole[];
46
+ emojis?: {
47
+ id: string;
48
+ name?: string;
49
+ }[];
50
+ stickers?: {
51
+ id: string;
52
+ name?: string;
53
+ }[];
54
+ }
55
+ export interface MicupGuildCreate extends MicupGuild {
56
+ properties?: Partial<MicupGuild>;
57
+ channels?: MicupChannel[];
58
+ threads?: MicupChannel[];
59
+ voice_states?: MicupVoiceState[];
60
+ members?: MicupMember[];
61
+ }
62
+ export interface MicupMembersChunk {
63
+ guild_id: string;
64
+ members: MicupMember[];
65
+ chunk_index: number;
66
+ chunk_count: number;
67
+ not_found?: string[];
68
+ nonce?: string;
69
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,137 @@
1
+ import type { MicupMessage, MicupUser } from '../rest/client.js';
2
+ import type { MicupChannel, MicupMember, MicupRole } from './guild.js';
3
+ export declare const InteractionType: {
4
+ readonly Ping: 1;
5
+ readonly Command: 2;
6
+ readonly Component: 3;
7
+ readonly Autocomplete: 4;
8
+ readonly Modal: 5;
9
+ };
10
+ export declare const CommandType: {
11
+ readonly ChatInput: 1;
12
+ readonly User: 2;
13
+ readonly Message: 3;
14
+ };
15
+ export declare const CommandOptionType: {
16
+ readonly Subcommand: 1;
17
+ readonly SubcommandGroup: 2;
18
+ readonly String: 3;
19
+ readonly Integer: 4;
20
+ readonly Boolean: 5;
21
+ readonly User: 6;
22
+ readonly Channel: 7;
23
+ readonly Role: 8;
24
+ readonly Mentionable: 9;
25
+ readonly Number: 10;
26
+ readonly Attachment: 11;
27
+ };
28
+ type Localizations = Readonly<Record<string, string>>;
29
+ export interface CommandChoice {
30
+ name: string;
31
+ value: string | number;
32
+ name_localizations?: Localizations;
33
+ }
34
+ export interface CommandOption {
35
+ type: number;
36
+ name: string;
37
+ description: string;
38
+ name_localizations?: Localizations;
39
+ description_localizations?: Localizations;
40
+ required?: boolean;
41
+ choices?: readonly CommandChoice[];
42
+ options?: readonly CommandOption[];
43
+ autocomplete?: boolean;
44
+ channel_types?: readonly number[];
45
+ min_value?: number;
46
+ max_value?: number;
47
+ min_length?: number;
48
+ max_length?: number;
49
+ }
50
+ export interface CommandDefinition {
51
+ name: string;
52
+ type?: number;
53
+ description?: string;
54
+ name_localizations?: Localizations;
55
+ description_localizations?: Localizations;
56
+ options?: readonly CommandOption[];
57
+ default_member_permissions?: string | null;
58
+ dm_permission?: boolean;
59
+ }
60
+ export interface MicupCommand extends CommandDefinition {
61
+ id: string;
62
+ application_id: string;
63
+ guild_id?: string;
64
+ version?: string;
65
+ }
66
+ export interface CommandOptionValue {
67
+ name: string;
68
+ type: number;
69
+ value?: string | number | boolean;
70
+ focused?: boolean;
71
+ options?: readonly CommandOptionValue[];
72
+ }
73
+ export interface CommandData {
74
+ id: string;
75
+ name: string;
76
+ type?: number;
77
+ options?: readonly CommandOptionValue[];
78
+ target_id?: string;
79
+ resolved?: {
80
+ users?: Record<string, MicupUser>;
81
+ members?: Record<string, MicupMember>;
82
+ roles?: Record<string, MicupRole>;
83
+ channels?: Record<string, MicupChannel>;
84
+ messages?: Record<string, MicupMessage>;
85
+ attachments?: Record<string, {
86
+ id: string;
87
+ filename: string;
88
+ url: string;
89
+ }>;
90
+ };
91
+ }
92
+ export interface ComponentData {
93
+ custom_id: string;
94
+ component_type: number;
95
+ values?: string[];
96
+ resolved?: CommandData['resolved'];
97
+ }
98
+ export interface ModalData {
99
+ custom_id: string;
100
+ components: readonly {
101
+ type: number;
102
+ components?: readonly {
103
+ type: number;
104
+ custom_id: string;
105
+ value: string;
106
+ }[];
107
+ }[];
108
+ }
109
+ interface InteractionContext {
110
+ id: string;
111
+ application_id: string;
112
+ token: string;
113
+ guild_id?: string;
114
+ channel_id?: string;
115
+ member?: MicupMember;
116
+ user?: MicupUser;
117
+ message?: MicupMessage;
118
+ channel?: MicupChannel;
119
+ locale?: string;
120
+ guild_locale?: string;
121
+ app_permissions?: string;
122
+ }
123
+ export type MicupInteraction = InteractionContext & ({
124
+ type: 1;
125
+ data?: undefined;
126
+ } | {
127
+ type: 2 | 4;
128
+ data: CommandData;
129
+ } | {
130
+ type: 3;
131
+ data: ComponentData;
132
+ } | {
133
+ type: 5;
134
+ data: ModalData;
135
+ });
136
+ export declare function commandPath(data: CommandData): string[];
137
+ export {};
@@ -0,0 +1,18 @@
1
+ export const InteractionType = { Ping: 1, Command: 2, Component: 3, Autocomplete: 4, Modal: 5 };
2
+ export const CommandType = { ChatInput: 1, User: 2, Message: 3 };
3
+ export const CommandOptionType = {
4
+ Subcommand: 1, SubcommandGroup: 2, String: 3, Integer: 4, Boolean: 5, User: 6,
5
+ Channel: 7, Role: 8, Mentionable: 9, Number: 10, Attachment: 11,
6
+ };
7
+ export function commandPath(data) {
8
+ const path = [data.name];
9
+ let options = data.options;
10
+ for (let depth = 0; depth < 2 && options?.length; depth++) {
11
+ const child = options.find((option) => option.type === 1 || option.type === 2);
12
+ if (!child)
13
+ break;
14
+ path.push(child.name);
15
+ options = child.options;
16
+ }
17
+ return path;
18
+ }
@@ -0,0 +1,47 @@
1
+ import type { MicupRole, PermissionOverwrite } from './guild.js';
2
+ export declare const Permission: {
3
+ readonly CreateInstantInvite: bigint;
4
+ readonly KickMembers: bigint;
5
+ readonly BanMembers: bigint;
6
+ readonly Administrator: bigint;
7
+ readonly ManageChannels: bigint;
8
+ readonly ManageGuild: bigint;
9
+ readonly AddReactions: bigint;
10
+ readonly ViewAuditLog: bigint;
11
+ readonly PrioritySpeaker: bigint;
12
+ readonly Stream: bigint;
13
+ readonly ViewChannel: bigint;
14
+ readonly SendMessages: bigint;
15
+ readonly SendTTSMessages: bigint;
16
+ readonly ManageMessages: bigint;
17
+ readonly EmbedLinks: bigint;
18
+ readonly AttachFiles: bigint;
19
+ readonly ReadMessageHistory: bigint;
20
+ readonly MentionEveryone: bigint;
21
+ readonly UseExternalEmojis: bigint;
22
+ readonly Connect: bigint;
23
+ readonly Speak: bigint;
24
+ readonly MuteMembers: bigint;
25
+ readonly DeafenMembers: bigint;
26
+ readonly MoveMembers: bigint;
27
+ readonly UseVAD: bigint;
28
+ readonly ChangeNickname: bigint;
29
+ readonly ManageNicknames: bigint;
30
+ readonly ManageRoles: bigint;
31
+ readonly ManageWebhooks: bigint;
32
+ readonly ManageExpressions: bigint;
33
+ readonly ManageThreads: bigint;
34
+ readonly CreatePublicThreads: bigint;
35
+ readonly CreatePrivateThreads: bigint;
36
+ readonly UseExternalStickers: bigint;
37
+ readonly SendMessagesInThreads: bigint;
38
+ readonly ModerateMembers: bigint;
39
+ readonly CreateExpressions: bigint;
40
+ readonly PinMessages: bigint;
41
+ readonly BypassSlowmode: bigint;
42
+ readonly UpdateRTCRegion: bigint;
43
+ readonly ViewChannelMembers: bigint;
44
+ readonly All: bigint;
45
+ };
46
+ export declare function hasPermissions(permissions: bigint, required: bigint): boolean;
47
+ export declare function computePermissions(guildId: string, ownerId: string | undefined, userId: string, roles: ReadonlyMap<string, MicupRole>, memberRoles: readonly string[], overwrites?: readonly PermissionOverwrite[]): bigint;
@@ -0,0 +1,81 @@
1
+ export const Permission = {
2
+ CreateInstantInvite: 1n << 0n,
3
+ KickMembers: 1n << 1n,
4
+ BanMembers: 1n << 2n,
5
+ Administrator: 1n << 3n,
6
+ ManageChannels: 1n << 4n,
7
+ ManageGuild: 1n << 5n,
8
+ AddReactions: 1n << 6n,
9
+ ViewAuditLog: 1n << 7n,
10
+ PrioritySpeaker: 1n << 8n,
11
+ Stream: 1n << 9n,
12
+ ViewChannel: 1n << 10n,
13
+ SendMessages: 1n << 11n,
14
+ SendTTSMessages: 1n << 12n,
15
+ ManageMessages: 1n << 13n,
16
+ EmbedLinks: 1n << 14n,
17
+ AttachFiles: 1n << 15n,
18
+ ReadMessageHistory: 1n << 16n,
19
+ MentionEveryone: 1n << 17n,
20
+ UseExternalEmojis: 1n << 18n,
21
+ Connect: 1n << 20n,
22
+ Speak: 1n << 21n,
23
+ MuteMembers: 1n << 22n,
24
+ DeafenMembers: 1n << 23n,
25
+ MoveMembers: 1n << 24n,
26
+ UseVAD: 1n << 25n,
27
+ ChangeNickname: 1n << 26n,
28
+ ManageNicknames: 1n << 27n,
29
+ ManageRoles: 1n << 28n,
30
+ ManageWebhooks: 1n << 29n,
31
+ ManageExpressions: 1n << 30n,
32
+ ManageThreads: 1n << 34n,
33
+ CreatePublicThreads: 1n << 35n,
34
+ CreatePrivateThreads: 1n << 36n,
35
+ UseExternalStickers: 1n << 37n,
36
+ SendMessagesInThreads: 1n << 38n,
37
+ ModerateMembers: 1n << 40n,
38
+ CreateExpressions: 1n << 43n,
39
+ PinMessages: 1n << 51n,
40
+ BypassSlowmode: 1n << 52n,
41
+ UpdateRTCRegion: 1n << 53n,
42
+ ViewChannelMembers: 1n << 54n,
43
+ All: (1n << 63n) - 1n,
44
+ };
45
+ function bits(value) {
46
+ if (typeof value === 'string' && /^\d{1,20}$/.test(value))
47
+ return BigInt(value);
48
+ if (typeof value === 'number' && Number.isSafeInteger(value) && value >= 0)
49
+ return BigInt(value);
50
+ return 0n;
51
+ }
52
+ export function hasPermissions(permissions, required) {
53
+ return (permissions & required) === required;
54
+ }
55
+ export function computePermissions(guildId, ownerId, userId, roles, memberRoles, overwrites = []) {
56
+ if (userId && userId === ownerId)
57
+ return Permission.All;
58
+ let permissions = bits(roles.get(guildId)?.permissions);
59
+ for (const id of memberRoles)
60
+ permissions |= bits(roles.get(id)?.permissions);
61
+ if (hasPermissions(permissions, Permission.Administrator))
62
+ return Permission.All;
63
+ const byId = new Map(overwrites.map((entry) => [entry.id, entry]));
64
+ const everyone = byId.get(guildId);
65
+ if (everyone)
66
+ permissions = (permissions & ~bits(everyone.deny)) | bits(everyone.allow);
67
+ let allow = 0n;
68
+ let deny = 0n;
69
+ for (const id of memberRoles) {
70
+ const entry = byId.get(id);
71
+ if (entry?.type === 0) {
72
+ allow |= bits(entry.allow);
73
+ deny |= bits(entry.deny);
74
+ }
75
+ }
76
+ permissions = (permissions & ~deny) | allow;
77
+ const user = byId.get(userId);
78
+ if (user?.type === 1)
79
+ permissions = (permissions & ~bits(user.deny)) | bits(user.allow);
80
+ return permissions;
81
+ }
@@ -0,0 +1,16 @@
1
+ export type PresenceStatus = 'online' | 'idle' | 'dnd' | 'invisible' | 'offline';
2
+ export interface CustomStatus {
3
+ text?: string;
4
+ expires_at?: string;
5
+ emoji_id?: string;
6
+ emoji_name?: string;
7
+ emoji_animated?: boolean;
8
+ }
9
+ export interface Presence {
10
+ status: PresenceStatus;
11
+ afk?: boolean;
12
+ mobile?: boolean;
13
+ custom_status?: CustomStatus | null;
14
+ }
15
+ export declare function normalizePresence(presence: Presence): Presence;
16
+ export declare function activePresence(presence: Presence): Presence;
@@ -0,0 +1,30 @@
1
+ export function normalizePresence(presence) {
2
+ if (!['online', 'idle', 'dnd', 'invisible', 'offline'].includes(presence.status)) {
3
+ throw new TypeError('Invalid Micup presence status');
4
+ }
5
+ const custom = presence.custom_status;
6
+ if (custom) {
7
+ if (!custom.text && !custom.emoji_id && !custom.emoji_name)
8
+ throw new TypeError('Custom status needs text or an emoji');
9
+ if ((custom.text?.length ?? 0) > 128 || (custom.emoji_name?.length ?? 0) > 32)
10
+ throw new RangeError('Custom status text or emoji is too long');
11
+ if (custom.emoji_id && !/^\d+$/.test(custom.emoji_id))
12
+ throw new TypeError('Invalid custom status emoji ID');
13
+ if (custom.expires_at && (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/i.test(custom.expires_at) ||
14
+ !Number.isFinite(Date.parse(custom.expires_at)) || Date.parse(custom.expires_at) <= Date.now())) {
15
+ throw new RangeError('Custom status expiry must be a future RFC 3339 timestamp');
16
+ }
17
+ }
18
+ return {
19
+ status: presence.status === 'offline' ? 'invisible' : presence.status,
20
+ afk: presence.afk ?? false,
21
+ mobile: presence.mobile ?? false,
22
+ custom_status: custom && { ...custom } || null,
23
+ };
24
+ }
25
+ export function activePresence(presence) {
26
+ const custom = presence.custom_status;
27
+ if (custom?.expires_at && Date.parse(custom.expires_at) <= Date.now())
28
+ return { ...presence, custom_status: null };
29
+ return presence;
30
+ }
@@ -0,0 +1,82 @@
1
+ import type { MicupChannel, PermissionOverwrite } from '../model/guild.js';
2
+ import type { MicupMessage, MicupUser } from './client.js';
3
+ import { type AuditOptions } from './guilds.js';
4
+ import type { MicupRequestOptions, RestTransport } from './transport.js';
5
+ export interface ChannelEdit {
6
+ name?: string;
7
+ topic?: string | null;
8
+ type?: number;
9
+ parent_id?: string | null;
10
+ bitrate?: number;
11
+ user_limit?: number;
12
+ position?: number;
13
+ permission_overwrites?: readonly PermissionOverwrite[];
14
+ archived?: boolean;
15
+ locked?: boolean;
16
+ auto_archive_duration?: number;
17
+ rate_limit_per_user?: number;
18
+ nsfw?: boolean;
19
+ }
20
+ export interface ThreadStart {
21
+ name: string;
22
+ type?: 10 | 11 | 12;
23
+ auto_archive_duration?: number;
24
+ rate_limit_per_user?: number;
25
+ invitable?: boolean;
26
+ }
27
+ export interface ThreadList {
28
+ threads: MicupChannel[];
29
+ has_more?: boolean;
30
+ members?: {
31
+ id?: string;
32
+ user_id?: string;
33
+ join_timestamp?: string;
34
+ }[];
35
+ first_messages?: MicupMessage[];
36
+ }
37
+ export interface MicupInvite {
38
+ code: string;
39
+ type?: number;
40
+ channel_id?: string;
41
+ guild_id?: string;
42
+ inviter?: MicupUser;
43
+ max_age?: number;
44
+ max_uses?: number;
45
+ expires_at?: string | null;
46
+ }
47
+ export declare class MicupChannels {
48
+ private readonly rest;
49
+ constructor(rest: RestTransport);
50
+ get(id: string, options?: MicupRequestOptions): Promise<MicupChannel>;
51
+ create(guildId: string, body: ChannelEdit & {
52
+ name: string;
53
+ }, options?: AuditOptions): Promise<MicupChannel>;
54
+ edit(id: string, body: ChannelEdit, options?: AuditOptions): Promise<MicupChannel>;
55
+ delete(id: string, options?: AuditOptions): Promise<void>;
56
+ setPermission(id: string, { id: target, ...body }: PermissionOverwrite, options?: AuditOptions): Promise<void>;
57
+ deletePermission(id: string, overwriteId: string, options?: AuditOptions): Promise<void>;
58
+ pin(id: string, messageId: string, options?: AuditOptions): Promise<void>;
59
+ unpin(id: string, messageId: string, options?: AuditOptions): Promise<void>;
60
+ pins(id: string, query?: URLSearchParams, options?: MicupRequestOptions): Promise<{
61
+ items: {
62
+ message: MicupMessage;
63
+ pinned_at: string;
64
+ }[];
65
+ has_more: boolean;
66
+ }>;
67
+ addReaction(id: string, messageId: string, emoji: string, options?: MicupRequestOptions): Promise<void>;
68
+ removeReaction(id: string, messageId: string, emoji: string, options?: MicupRequestOptions): Promise<void>;
69
+ startThread(id: string, body: ThreadStart, options?: AuditOptions & {
70
+ messageId?: string;
71
+ }): Promise<MicupChannel>;
72
+ activeThreads(guildId: string, options?: MicupRequestOptions): Promise<ThreadList>;
73
+ joinThread(threadId: string, options?: MicupRequestOptions): Promise<void>;
74
+ leaveThread(threadId: string, options?: MicupRequestOptions): Promise<void>;
75
+ invites(channelId: string, options?: MicupRequestOptions): Promise<MicupInvite[]>;
76
+ createInvite(channelId: string, body?: {
77
+ max_uses?: number;
78
+ max_age?: number;
79
+ temporary?: boolean;
80
+ unique?: boolean;
81
+ }, options?: AuditOptions): Promise<MicupInvite>;
82
+ }
@@ -0,0 +1,68 @@
1
+ import { guildPath } from './guilds.js';
2
+ import { messagesPath, snowflake } from './messages.js';
3
+ function channelPath(channelId) {
4
+ return '/channels/' + snowflake(channelId, 'Channel ID');
5
+ }
6
+ function reactionPath(channelId, messageId, emoji) {
7
+ if (!emoji || Buffer.byteLength(emoji) > 64 || emoji === '.' || emoji === '..')
8
+ throw new TypeError('Invalid Micup emoji');
9
+ return messagesPath(channelId, messageId) + '/reactions/' + encodeURIComponent(emoji);
10
+ }
11
+ export class MicupChannels {
12
+ rest;
13
+ constructor(rest) {
14
+ this.rest = rest;
15
+ }
16
+ get(id, options) {
17
+ return this.rest.request('GET', channelPath(id), options);
18
+ }
19
+ create(guildId, body, options) {
20
+ return this.rest.request('POST', guildPath(guildId) + '/channels', { ...options, body });
21
+ }
22
+ edit(id, body, options) {
23
+ return this.rest.request('PATCH', channelPath(id), { ...options, body });
24
+ }
25
+ delete(id, options) {
26
+ return this.rest.request('DELETE', channelPath(id), options);
27
+ }
28
+ setPermission(id, { id: target, ...body }, options) {
29
+ return this.rest.request('PUT', channelPath(id) + '/permissions/' + snowflake(target, 'Overwrite ID'), { ...options, body });
30
+ }
31
+ deletePermission(id, overwriteId, options) {
32
+ return this.rest.request('DELETE', channelPath(id) + '/permissions/' + snowflake(overwriteId, 'Overwrite ID'), options);
33
+ }
34
+ pin(id, messageId, options) {
35
+ return this.rest.request('PUT', channelPath(id) + '/pins/' + snowflake(messageId, 'Message ID'), options);
36
+ }
37
+ unpin(id, messageId, options) {
38
+ return this.rest.request('DELETE', channelPath(id) + '/pins/' + snowflake(messageId, 'Message ID'), options);
39
+ }
40
+ pins(id, query, options) {
41
+ return this.rest.request('GET', messagesPath(id) + '/pins', { ...options, query });
42
+ }
43
+ addReaction(id, messageId, emoji, options) {
44
+ return this.rest.request('PUT', reactionPath(id, messageId, emoji) + '/@me', options);
45
+ }
46
+ removeReaction(id, messageId, emoji, options) {
47
+ return this.rest.request('DELETE', reactionPath(id, messageId, emoji) + '/@me', options);
48
+ }
49
+ startThread(id, body, options = {}) {
50
+ const base = options.messageId === undefined ? channelPath(id) : messagesPath(id, options.messageId);
51
+ return this.rest.request('POST', base + '/threads', { ...options, body });
52
+ }
53
+ activeThreads(guildId, options) {
54
+ return this.rest.request('GET', guildPath(guildId) + '/threads/active', options);
55
+ }
56
+ joinThread(threadId, options) {
57
+ return this.rest.request('PUT', channelPath(threadId) + '/thread-members/@me', options);
58
+ }
59
+ leaveThread(threadId, options) {
60
+ return this.rest.request('DELETE', channelPath(threadId) + '/thread-members/@me', options);
61
+ }
62
+ invites(channelId, options) {
63
+ return this.rest.request('GET', channelPath(channelId) + '/invites', options);
64
+ }
65
+ createInvite(channelId, body = {}, options) {
66
+ return this.rest.request('POST', channelPath(channelId) + '/invites', { ...options, body });
67
+ }
68
+ }
@@ -0,0 +1,48 @@
1
+ import { GatewaySession, type GatewaySessionConfig, type GatewaySessionOptions } from '../session/session.js';
2
+ import { ShardManager, type ShardManagerOptions } from '../shard/manager.js';
3
+ import { type MicupRequestOptions, type RestMethod, type RestRequestOptions } from './transport.js';
4
+ import { type ListMessageOptions, type MessageInput } from './messages.js';
5
+ import { MicupCommands } from './commands.js';
6
+ import { MicupInteractions } from './interactions.js';
7
+ import { MicupGuilds } from './guilds.js';
8
+ import { MicupChannels } from './channels.js';
9
+ export interface MicupClientOptions {
10
+ token: string;
11
+ origin?: string;
12
+ maxRestAttempts?: number;
13
+ }
14
+ export interface MicupUser {
15
+ id: string;
16
+ username: string;
17
+ bot?: boolean;
18
+ }
19
+ export interface MicupMessage {
20
+ id: string;
21
+ channel_id: string;
22
+ content: string;
23
+ author: MicupUser;
24
+ }
25
+ export declare class MicupClient {
26
+ #private;
27
+ readonly interactions: MicupInteractions;
28
+ readonly guilds: MicupGuilds;
29
+ readonly channels: MicupChannels;
30
+ private constructor();
31
+ static connect({ token, origin, maxRestAttempts }: MicupClientOptions, { signal }?: MicupRequestOptions): Promise<MicupClient>;
32
+ get commands(): MicupCommands;
33
+ newSession(options: GatewaySessionOptions, shard?: Pick<GatewaySessionConfig, 'shardId' | 'shardCount'>): GatewaySession;
34
+ newShardManager(options: ShardManagerOptions): ShardManager;
35
+ getCurrentUser({ signal }?: MicupRequestOptions): Promise<MicupUser>;
36
+ sendMessage(channelId: string, content: string | MessageInput, { replyTo, signal }?: MicupRequestOptions & {
37
+ replyTo?: string;
38
+ }): Promise<MicupMessage>;
39
+ getMessage(channelId: string, messageId: string, options?: MicupRequestOptions): Promise<MicupMessage>;
40
+ listMessages(channelId: string, options?: ListMessageOptions): Promise<MicupMessage[]>;
41
+ iterateMessages(channelId: string, options?: Omit<ListMessageOptions, 'around' | 'limit'>): AsyncGenerator<MicupMessage>;
42
+ editMessage(channelId: string, messageId: string, edit: MessageInput, options?: MicupRequestOptions): Promise<MicupMessage>;
43
+ deleteMessage(channelId: string, messageId: string, options?: MicupRequestOptions & {
44
+ reason?: string;
45
+ }): Promise<void>;
46
+ triggerTyping(channelId: string, options?: MicupRequestOptions): Promise<void>;
47
+ request<T = unknown>(method: RestMethod, path: string, options?: RestRequestOptions): Promise<T>;
48
+ }