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/rest/errors.js
CHANGED
|
@@ -4,6 +4,40 @@ export function retryDelay(value) {
|
|
|
4
4
|
const seconds = Number(value);
|
|
5
5
|
return Number.isFinite(seconds) && seconds > 0 ? Math.min(2_147_483_647, Math.ceil(seconds * 1000)) : 0;
|
|
6
6
|
}
|
|
7
|
+
export const MicupErrorCode = Object.freeze({
|
|
8
|
+
InvalidFormBody: 'INVALID_FORM_BODY',
|
|
9
|
+
RateLimited: 'RATE_LIMITED',
|
|
10
|
+
NewDMRateLimited: 'NEW_DM_RATE_LIMITED',
|
|
11
|
+
SlowmodeRateLimited: 'SLOWMODE_RATE_LIMITED',
|
|
12
|
+
ResourceLocked: 'RESOURCE_LOCKED',
|
|
13
|
+
Unauthorized: 'UNAUTHORIZED',
|
|
14
|
+
MissingAccess: 'MISSING_ACCESS',
|
|
15
|
+
MissingPermissions: 'MISSING_PERMISSIONS',
|
|
16
|
+
TwoFactorRequired: 'TWO_FACTOR_REQUIRED',
|
|
17
|
+
CommunicationDisabled: 'COMMUNICATION_DISABLED',
|
|
18
|
+
ContentBlocked: 'CONTENT_BLOCKED',
|
|
19
|
+
SpamBlocked: 'SPAM_BLOCKED',
|
|
20
|
+
CannotSendEmptyMessage: 'CANNOT_SEND_EMPTY_MESSAGE',
|
|
21
|
+
UnknownChannel: 'UNKNOWN_CHANNEL',
|
|
22
|
+
UnknownGuild: 'UNKNOWN_GUILD',
|
|
23
|
+
UnknownMember: 'UNKNOWN_MEMBER',
|
|
24
|
+
UnknownMessage: 'UNKNOWN_MESSAGE',
|
|
25
|
+
UnknownRole: 'UNKNOWN_ROLE',
|
|
26
|
+
UnknownUser: 'UNKNOWN_USER',
|
|
27
|
+
UnknownInvite: 'UNKNOWN_INVITE',
|
|
28
|
+
UnknownEmoji: 'UNKNOWN_EMOJI',
|
|
29
|
+
UnknownSticker: 'UNKNOWN_STICKER',
|
|
30
|
+
UnknownWebhook: 'UNKNOWN_WEBHOOK',
|
|
31
|
+
ThreadArchived: 'THREAD_ARCHIVED',
|
|
32
|
+
ThreadLocked: 'THREAD_LOCKED',
|
|
33
|
+
MaxActiveThreads: 'MAX_ACTIVE_THREADS',
|
|
34
|
+
NsfwAgeRestricted: 'NSFW_CONTENT_AGE_RESTRICTED',
|
|
35
|
+
FeatureTemporarilyDisabled: 'FEATURE_TEMPORARILY_DISABLED',
|
|
36
|
+
VoiceRoomNotActive: 'VOICE_ROOM_NOT_ACTIVE',
|
|
37
|
+
RoomTournamentConflict: 'ROOM_TOURNAMENT_CONFLICT',
|
|
38
|
+
UnknownRoomTournament: 'UNKNOWN_ROOM_TOURNAMENT',
|
|
39
|
+
SudoModeRequired: 'SUDO_MODE_REQUIRED',
|
|
40
|
+
});
|
|
7
41
|
export class MicupAPIError extends Error {
|
|
8
42
|
status;
|
|
9
43
|
code;
|
|
@@ -23,4 +57,16 @@ export class MicupAPIError extends Error {
|
|
|
23
57
|
this.global = body?.global === true || response.headers.get('x-ratelimit-global') === 'true';
|
|
24
58
|
this.errors = Array.isArray(body?.errors) ? body.errors : [];
|
|
25
59
|
}
|
|
60
|
+
get notFound() {
|
|
61
|
+
return this.status === 404;
|
|
62
|
+
}
|
|
63
|
+
get forbidden() {
|
|
64
|
+
return this.status === 403;
|
|
65
|
+
}
|
|
66
|
+
get rateLimited() {
|
|
67
|
+
return this.status === 429;
|
|
68
|
+
}
|
|
69
|
+
hasFieldCode(code) {
|
|
70
|
+
return this.errors.some((error) => error.code === code);
|
|
71
|
+
}
|
|
26
72
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Emoji } from '../model/format.js';
|
|
2
|
+
import type { AuditOptions } from './guilds.js';
|
|
3
|
+
import type { MicupRequestOptions, RestTransport } from './transport.js';
|
|
4
|
+
export interface EmojiInput {
|
|
5
|
+
name: string;
|
|
6
|
+
image: string;
|
|
7
|
+
}
|
|
8
|
+
export interface StickerInput {
|
|
9
|
+
name: string;
|
|
10
|
+
image: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
tags?: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
export interface MicupSticker {
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
tags?: string[];
|
|
19
|
+
format_type?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface ExpressionMetadata {
|
|
22
|
+
id: string;
|
|
23
|
+
guild_id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
animated: boolean;
|
|
26
|
+
allow_cloning: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface ExpressionSourceGuild {
|
|
29
|
+
id: string;
|
|
30
|
+
name: string;
|
|
31
|
+
icon: string | null;
|
|
32
|
+
features: string[];
|
|
33
|
+
}
|
|
34
|
+
export interface ExpressionBulkResult<T> {
|
|
35
|
+
success: T[];
|
|
36
|
+
failed: {
|
|
37
|
+
name?: string;
|
|
38
|
+
error?: string;
|
|
39
|
+
index?: number;
|
|
40
|
+
}[];
|
|
41
|
+
}
|
|
42
|
+
type Resource = 'emojis' | 'stickers';
|
|
43
|
+
export declare class MicupExpressions {
|
|
44
|
+
#private;
|
|
45
|
+
private readonly rest;
|
|
46
|
+
constructor(rest: RestTransport);
|
|
47
|
+
listEmojis(guildId: string, options?: MicupRequestOptions): Promise<Emoji[]>;
|
|
48
|
+
listStickers(guildId: string, options?: MicupRequestOptions): Promise<MicupSticker[]>;
|
|
49
|
+
createEmoji(guildId: string, body: EmojiInput, options?: AuditOptions): Promise<Emoji>;
|
|
50
|
+
createSticker(guildId: string, body: StickerInput, options?: AuditOptions): Promise<MicupSticker>;
|
|
51
|
+
createEmojis(guildId: string, emojis: readonly EmojiInput[], options?: AuditOptions): Promise<ExpressionBulkResult<Emoji>>;
|
|
52
|
+
createStickers(guildId: string, stickers: readonly StickerInput[], options?: AuditOptions): Promise<ExpressionBulkResult<MicupSticker>>;
|
|
53
|
+
cloneEmoji(guildId: string, source: string, options?: AuditOptions): Promise<Emoji>;
|
|
54
|
+
cloneSticker(guildId: string, source: string, options?: AuditOptions): Promise<MicupSticker>;
|
|
55
|
+
renameEmoji(guildId: string, id: string, name: string, options?: AuditOptions): Promise<Emoji>;
|
|
56
|
+
editSticker(guildId: string, id: string, body: Omit<StickerInput, 'image'>, options?: AuditOptions): Promise<MicupSticker>;
|
|
57
|
+
delete(guildId: string, kind: Resource, id: string, { purge, ...options }?: AuditOptions & {
|
|
58
|
+
purge?: boolean;
|
|
59
|
+
}): Promise<void>;
|
|
60
|
+
emoji(guildId: string, id: string, options?: MicupRequestOptions): Promise<Emoji>;
|
|
61
|
+
sticker(guildId: string, id: string, options?: MicupRequestOptions): Promise<MicupSticker>;
|
|
62
|
+
source(kind: Resource, id: string, options?: MicupRequestOptions): Promise<ExpressionSourceGuild>;
|
|
63
|
+
metadata(kind: Resource, id: string, options?: MicupRequestOptions): Promise<ExpressionMetadata>;
|
|
64
|
+
}
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { guildPath } from './guilds.js';
|
|
2
|
+
import { snowflake } from './messages.js';
|
|
3
|
+
function emojiName(name) {
|
|
4
|
+
if (!/^[A-Za-z0-9_]{2,32}$/.test(name))
|
|
5
|
+
throw new TypeError('Emoji names need 2 to 32 ASCII letters, digits or underscores');
|
|
6
|
+
}
|
|
7
|
+
function stickerText({ name, description, tags }) {
|
|
8
|
+
if (![...name].length || [...name].length < 2 || [...name].length > 30 ||
|
|
9
|
+
(description !== undefined && [...description].length > 500) ||
|
|
10
|
+
(tags !== undefined && (tags.length > 10 || tags.some((tag) => !tag || [...tag].length > 30)))) {
|
|
11
|
+
throw new TypeError('Invalid Micup sticker name, description or tags');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function createEmoji(item) {
|
|
15
|
+
emojiName(item.name);
|
|
16
|
+
if (!item.image)
|
|
17
|
+
throw new TypeError('An emoji image is required');
|
|
18
|
+
}
|
|
19
|
+
function createSticker(item) {
|
|
20
|
+
stickerText(item);
|
|
21
|
+
if (!item.image)
|
|
22
|
+
throw new TypeError('A sticker image is required');
|
|
23
|
+
}
|
|
24
|
+
export class MicupExpressions {
|
|
25
|
+
rest;
|
|
26
|
+
constructor(rest) {
|
|
27
|
+
this.rest = rest;
|
|
28
|
+
}
|
|
29
|
+
#path(guildId, kind, id) {
|
|
30
|
+
const base = guildPath(guildId) + '/' + kind;
|
|
31
|
+
return id === undefined ? base : base + '/' + snowflake(id, 'Expression ID');
|
|
32
|
+
}
|
|
33
|
+
listEmojis(guildId, options) {
|
|
34
|
+
return this.rest.request('GET', this.#path(guildId, 'emojis'), options);
|
|
35
|
+
}
|
|
36
|
+
listStickers(guildId, options) {
|
|
37
|
+
return this.rest.request('GET', this.#path(guildId, 'stickers'), options);
|
|
38
|
+
}
|
|
39
|
+
createEmoji(guildId, body, options) {
|
|
40
|
+
createEmoji(body);
|
|
41
|
+
return this.rest.request('POST', this.#path(guildId, 'emojis'), { ...options, body });
|
|
42
|
+
}
|
|
43
|
+
createSticker(guildId, body, options) {
|
|
44
|
+
createSticker(body);
|
|
45
|
+
return this.rest.request('POST', this.#path(guildId, 'stickers'), { ...options, body });
|
|
46
|
+
}
|
|
47
|
+
createEmojis(guildId, emojis, options) {
|
|
48
|
+
if (!emojis.length || emojis.length > 50)
|
|
49
|
+
throw new RangeError('A bulk create takes up to 50 emojis');
|
|
50
|
+
emojis.forEach(createEmoji);
|
|
51
|
+
return this.rest.request('POST', this.#path(guildId, 'emojis') + '/bulk', { ...options, body: { emojis } });
|
|
52
|
+
}
|
|
53
|
+
createStickers(guildId, stickers, options) {
|
|
54
|
+
if (!stickers.length || stickers.length > 50)
|
|
55
|
+
throw new RangeError('A bulk create takes up to 50 stickers');
|
|
56
|
+
stickers.forEach(createSticker);
|
|
57
|
+
return this.rest.request('POST', this.#path(guildId, 'stickers') + '/bulk', { ...options, body: { stickers } });
|
|
58
|
+
}
|
|
59
|
+
cloneEmoji(guildId, source, options) {
|
|
60
|
+
return this.rest.request('POST', this.#path(guildId, 'emojis') + '/clone', { ...options, body: { source_emoji_id: snowflake(source, 'Source emoji ID') } });
|
|
61
|
+
}
|
|
62
|
+
cloneSticker(guildId, source, options) {
|
|
63
|
+
return this.rest.request('POST', this.#path(guildId, 'stickers') + '/clone', { ...options, body: { source_sticker_id: snowflake(source, 'Source sticker ID') } });
|
|
64
|
+
}
|
|
65
|
+
renameEmoji(guildId, id, name, options) {
|
|
66
|
+
emojiName(name);
|
|
67
|
+
return this.rest.request('PATCH', this.#path(guildId, 'emojis', id), { ...options, body: { name } });
|
|
68
|
+
}
|
|
69
|
+
editSticker(guildId, id, body, options) {
|
|
70
|
+
stickerText(body);
|
|
71
|
+
return this.rest.request('PATCH', this.#path(guildId, 'stickers', id), { ...options, body: { tags: [], ...body } });
|
|
72
|
+
}
|
|
73
|
+
delete(guildId, kind, id, { purge, ...options } = {}) {
|
|
74
|
+
const query = purge ? new URLSearchParams({ purge: 'true' }) : undefined;
|
|
75
|
+
return this.rest.request('DELETE', this.#path(guildId, kind, id), { ...options, query });
|
|
76
|
+
}
|
|
77
|
+
emoji(guildId, id, options) {
|
|
78
|
+
return this.rest.request('GET', this.#path(guildId, 'emojis', id), options);
|
|
79
|
+
}
|
|
80
|
+
sticker(guildId, id, options) {
|
|
81
|
+
return this.rest.request('GET', this.#path(guildId, 'stickers', id), options);
|
|
82
|
+
}
|
|
83
|
+
source(kind, id, options) {
|
|
84
|
+
return this.rest.request('GET', '/' + kind + '/' + snowflake(id, 'Expression ID') + '/source', options);
|
|
85
|
+
}
|
|
86
|
+
metadata(kind, id, options) {
|
|
87
|
+
return this.rest.request('GET', '/' + kind + '/' + snowflake(id, 'Expression ID') + '/metadata', options);
|
|
88
|
+
}
|
|
89
|
+
}
|
package/dist/rest/guilds.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MicupChannel, MicupGuild, MicupMember, MicupRole } from '../model/guild.js';
|
|
2
|
-
import type { MicupUser } from '
|
|
2
|
+
import type { MicupUser } from '../model/entities.js';
|
|
3
3
|
import type { MicupRequestOptions, RestTransport } from './transport.js';
|
|
4
4
|
export interface AuditOptions extends MicupRequestOptions {
|
|
5
5
|
reason?: string;
|
|
@@ -15,6 +15,33 @@ export interface GuildMemberEdit {
|
|
|
15
15
|
deaf?: boolean;
|
|
16
16
|
communication_disabled_until?: string | null;
|
|
17
17
|
channel_id?: string | null;
|
|
18
|
+
connection_id?: string;
|
|
19
|
+
timeout_reason?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ChannelPosition {
|
|
22
|
+
id: string;
|
|
23
|
+
position?: number;
|
|
24
|
+
parent_id?: string | null;
|
|
25
|
+
preceding_sibling_id?: string | null;
|
|
26
|
+
lock_permissions?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface SudoProof {
|
|
29
|
+
password?: string;
|
|
30
|
+
mfa_method?: 'totp' | 'webauthn' | 'email_code';
|
|
31
|
+
mfa_code?: string;
|
|
32
|
+
webauthn_response?: unknown;
|
|
33
|
+
webauthn_challenge?: string;
|
|
34
|
+
email_code_ticket?: string;
|
|
35
|
+
email_code?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface CurrentMemberEdit extends Omit<GuildMemberEdit, 'roles'> {
|
|
38
|
+
avatar?: string | null;
|
|
39
|
+
banner?: string | null;
|
|
40
|
+
bio?: string | null;
|
|
41
|
+
pronouns?: string | null;
|
|
42
|
+
accent_color?: number | null;
|
|
43
|
+
profile_flags?: number;
|
|
44
|
+
mention_flags?: number;
|
|
18
45
|
}
|
|
19
46
|
export interface GuildRoleEdit {
|
|
20
47
|
name?: string;
|
|
@@ -51,8 +78,46 @@ export interface GuildAuditLog {
|
|
|
51
78
|
name?: string;
|
|
52
79
|
}[];
|
|
53
80
|
}
|
|
81
|
+
export interface GuildMemberSearch {
|
|
82
|
+
query?: string;
|
|
83
|
+
limit?: number;
|
|
84
|
+
offset?: number;
|
|
85
|
+
role_ids?: readonly string[];
|
|
86
|
+
join_source_type?: readonly number[];
|
|
87
|
+
source_invite_code?: readonly string[];
|
|
88
|
+
is_bot?: boolean;
|
|
89
|
+
joined_at_gte?: number;
|
|
90
|
+
joined_at_lte?: number;
|
|
91
|
+
user_created_at_gte?: number;
|
|
92
|
+
user_created_at_lte?: number;
|
|
93
|
+
sort_by?: string;
|
|
94
|
+
sort_order?: 'asc' | 'desc';
|
|
95
|
+
}
|
|
96
|
+
export interface GuildMemberSearchPage {
|
|
97
|
+
guild_id: string;
|
|
98
|
+
members: {
|
|
99
|
+
id: string;
|
|
100
|
+
guild_id: string;
|
|
101
|
+
user_id: string;
|
|
102
|
+
username: string;
|
|
103
|
+
global_name?: string | null;
|
|
104
|
+
nickname?: string | null;
|
|
105
|
+
role_ids: string[];
|
|
106
|
+
joined_at: number;
|
|
107
|
+
is_bot: boolean;
|
|
108
|
+
supplemental?: {
|
|
109
|
+
join_source_type?: number | null;
|
|
110
|
+
source_invite_code?: string | null;
|
|
111
|
+
inviter_id?: string | null;
|
|
112
|
+
};
|
|
113
|
+
}[];
|
|
114
|
+
page_result_count: number;
|
|
115
|
+
total_result_count: number;
|
|
116
|
+
indexing: boolean;
|
|
117
|
+
}
|
|
54
118
|
export declare function guildPath(id: string): string;
|
|
55
119
|
export declare class MicupGuilds {
|
|
120
|
+
#private;
|
|
56
121
|
private readonly rest;
|
|
57
122
|
constructor(rest: RestTransport);
|
|
58
123
|
get(guildId: string, options?: MicupRequestOptions): Promise<MicupGuild>;
|
|
@@ -62,6 +127,15 @@ export declare class MicupGuilds {
|
|
|
62
127
|
createRole(guildId: string, role: GuildRoleEdit, options?: AuditOptions): Promise<MicupRole>;
|
|
63
128
|
editRole(guildId: string, roleId: string, role: GuildRoleEdit, options?: AuditOptions): Promise<MicupRole>;
|
|
64
129
|
deleteRole(guildId: string, roleId: string, options?: AuditOptions): Promise<void>;
|
|
130
|
+
moveRoles(guildId: string, positions: readonly {
|
|
131
|
+
id: string;
|
|
132
|
+
position: number;
|
|
133
|
+
}[], options?: AuditOptions): Promise<void>;
|
|
134
|
+
moveHoistedRoles(guildId: string, positions: readonly {
|
|
135
|
+
id: string;
|
|
136
|
+
hoist_position: number;
|
|
137
|
+
}[], options?: AuditOptions): Promise<void>;
|
|
138
|
+
resetHoistedRoles(guildId: string, options?: AuditOptions): Promise<void>;
|
|
65
139
|
member(guildId: string, userId: string, options?: MicupRequestOptions): Promise<MicupMember>;
|
|
66
140
|
currentMember(guildId: string, options?: MicupRequestOptions): Promise<MicupMember>;
|
|
67
141
|
members(guildId: string, { limit, after, signal }?: GuildMemberQuery): Promise<MicupMember[]>;
|
|
@@ -72,5 +146,32 @@ export declare class MicupGuilds {
|
|
|
72
146
|
bans(guildId: string, options?: MicupRequestOptions): Promise<GuildBan[]>;
|
|
73
147
|
ban(guildId: string, userId: string, body?: GuildBanInput, options?: AuditOptions): Promise<void>;
|
|
74
148
|
unban(guildId: string, userId: string, options?: AuditOptions): Promise<void>;
|
|
149
|
+
timeout(guildId: string, userId: string, durationMs: number, options?: AuditOptions & {
|
|
150
|
+
timeoutReason?: string;
|
|
151
|
+
}): Promise<MicupMember>;
|
|
152
|
+
clearTimeout(guildId: string, userId: string, options?: AuditOptions): Promise<MicupMember>;
|
|
153
|
+
searchMembers(guildId: string, search: GuildMemberSearch, options?: MicupRequestOptions): Promise<GuildMemberSearchPage>;
|
|
154
|
+
moveChannels(guildId: string, positions: readonly ChannelPosition[], options?: MicupRequestOptions): Promise<void>;
|
|
155
|
+
getBan(guildId: string, userId: string, options?: MicupRequestOptions): Promise<GuildBan>;
|
|
156
|
+
role(guildId: string, roleId: string, options?: MicupRequestOptions): Promise<MicupRole>;
|
|
157
|
+
vanityUrl(guildId: string, options?: MicupRequestOptions): Promise<{
|
|
158
|
+
code: string | null;
|
|
159
|
+
uses: number;
|
|
160
|
+
}>;
|
|
161
|
+
editVanityUrl(guildId: string, code: string | null, options?: AuditOptions): Promise<{
|
|
162
|
+
code: string | null;
|
|
163
|
+
}>;
|
|
164
|
+
editCurrentMember(guildId: string, edit: CurrentMemberEdit, options?: AuditOptions): Promise<MicupMember>;
|
|
165
|
+
setNickname(guildId: string, nick: string | null, options?: AuditOptions): Promise<MicupMember>;
|
|
166
|
+
findMembers(guildId: string, query: string, { limit, signal }?: MicupRequestOptions & {
|
|
167
|
+
limit?: number;
|
|
168
|
+
}): Promise<MicupMember[]>;
|
|
169
|
+
transferOwnership(guildId: string, newOwnerId: string, { signal, reason, ...proof }?: AuditOptions & SudoProof): Promise<MicupGuild>;
|
|
170
|
+
deleteOwnMessages(guildId: string, { signal, ...proof }?: MicupRequestOptions & SudoProof): Promise<void>;
|
|
171
|
+
iterateMembers(guildId: string, { signal }?: MicupRequestOptions): AsyncGenerator<MicupMember>;
|
|
172
|
+
iterateAuditLog(guildId: string, { userId, actionType, signal }?: MicupRequestOptions & {
|
|
173
|
+
userId?: string;
|
|
174
|
+
actionType?: number;
|
|
175
|
+
}): AsyncGenerator<GuildAuditLog['audit_log_entries'][number]>;
|
|
75
176
|
auditLog(guildId: string, query?: URLSearchParams, options?: MicupRequestOptions): Promise<GuildAuditLog>;
|
|
76
177
|
}
|
package/dist/rest/guilds.js
CHANGED
|
@@ -40,6 +40,24 @@ export class MicupGuilds {
|
|
|
40
40
|
deleteRole(guildId, roleId, options) {
|
|
41
41
|
return this.rest.request('DELETE', guildPath(guildId) + '/roles/' + snowflake(roleId, 'Role ID'), options);
|
|
42
42
|
}
|
|
43
|
+
moveRoles(guildId, positions, options) {
|
|
44
|
+
this.#checkPositions(guildId, positions.map((entry) => ({ id: entry.id, position: entry.position })));
|
|
45
|
+
return this.rest.request('PATCH', guildPath(guildId) + '/roles', { ...options, body: positions });
|
|
46
|
+
}
|
|
47
|
+
moveHoistedRoles(guildId, positions, options) {
|
|
48
|
+
this.#checkPositions(guildId, positions.map((entry) => ({ id: entry.id, position: entry.hoist_position })));
|
|
49
|
+
return this.rest.request('PATCH', guildPath(guildId) + '/roles/hoist-positions', { ...options, body: positions });
|
|
50
|
+
}
|
|
51
|
+
resetHoistedRoles(guildId, options) {
|
|
52
|
+
return this.rest.request('DELETE', guildPath(guildId) + '/roles/hoist-positions', options);
|
|
53
|
+
}
|
|
54
|
+
#checkPositions(guildId, positions) {
|
|
55
|
+
if (!positions.length || positions.some(({ id, position }) => id === guildId || !Number.isSafeInteger(position) || position < 0)) {
|
|
56
|
+
throw new RangeError('Role positions require nonnegative positions and exclude the everyone role');
|
|
57
|
+
}
|
|
58
|
+
for (const { id } of positions)
|
|
59
|
+
snowflake(id, 'Role ID');
|
|
60
|
+
}
|
|
43
61
|
member(guildId, userId, options) {
|
|
44
62
|
return this.rest.request('GET', memberPath(guildId, userId), options);
|
|
45
63
|
}
|
|
@@ -84,6 +102,115 @@ export class MicupGuilds {
|
|
|
84
102
|
unban(guildId, userId, options) {
|
|
85
103
|
return this.rest.request('DELETE', guildPath(guildId) + '/bans/' + snowflake(userId, 'User ID'), options);
|
|
86
104
|
}
|
|
105
|
+
timeout(guildId, userId, durationMs, options = {}) {
|
|
106
|
+
const { timeoutReason, ...audit } = options;
|
|
107
|
+
if (!Number.isSafeInteger(durationMs) || durationMs <= 0 || durationMs > 365 * 24 * 60 * 60 * 1000) {
|
|
108
|
+
throw new RangeError('A Micup member timeout must be longer than zero and at most 365 days');
|
|
109
|
+
}
|
|
110
|
+
if (timeoutReason && [...timeoutReason].length > 512)
|
|
111
|
+
throw new RangeError('A timeout reason must contain at most 512 characters');
|
|
112
|
+
return this.editMember(guildId, userId, {
|
|
113
|
+
communication_disabled_until: new Date(Date.now() + durationMs).toISOString(), timeout_reason: timeoutReason,
|
|
114
|
+
}, audit);
|
|
115
|
+
}
|
|
116
|
+
clearTimeout(guildId, userId, options) {
|
|
117
|
+
return this.editMember(guildId, userId, { communication_disabled_until: null }, options);
|
|
118
|
+
}
|
|
119
|
+
searchMembers(guildId, search, options) {
|
|
120
|
+
const { query = '', limit = 100, offset = 0, role_ids, join_source_type, source_invite_code } = search;
|
|
121
|
+
if ([...query].length > 100 || !Number.isSafeInteger(limit) || limit < 1 || limit > 100 ||
|
|
122
|
+
!Number.isSafeInteger(offset) || offset < 0 ||
|
|
123
|
+
[role_ids, join_source_type, source_invite_code].some((values) => (values?.length ?? 0) > 10)) {
|
|
124
|
+
throw new RangeError('Invalid member search limit, offset, query or filters');
|
|
125
|
+
}
|
|
126
|
+
role_ids?.forEach((id) => snowflake(id, 'Role ID'));
|
|
127
|
+
return this.rest.request('POST', guildPath(guildId) + '/members-search', { ...options, body: search, idempotent: true });
|
|
128
|
+
}
|
|
129
|
+
moveChannels(guildId, positions, options) {
|
|
130
|
+
if (!positions.length)
|
|
131
|
+
throw new RangeError('Moving channels needs at least one position');
|
|
132
|
+
const body = positions.map(({ id, parent_id, preceding_sibling_id, ...position }) => ({
|
|
133
|
+
...position,
|
|
134
|
+
id: snowflake(id, 'Channel ID'),
|
|
135
|
+
...(parent_id !== undefined && { parent_id: parent_id === null ? null : snowflake(parent_id, 'Parent ID') }),
|
|
136
|
+
...(preceding_sibling_id !== undefined && {
|
|
137
|
+
preceding_sibling_id: preceding_sibling_id === null ? null : snowflake(preceding_sibling_id, 'Sibling ID'),
|
|
138
|
+
}),
|
|
139
|
+
}));
|
|
140
|
+
return this.rest.request('PATCH', guildPath(guildId) + '/channels', { ...options, body });
|
|
141
|
+
}
|
|
142
|
+
getBan(guildId, userId, options) {
|
|
143
|
+
return this.rest.request('GET', guildPath(guildId) + '/bans/' + snowflake(userId, 'User ID'), options);
|
|
144
|
+
}
|
|
145
|
+
role(guildId, roleId, options) {
|
|
146
|
+
return this.rest.request('GET', guildPath(guildId) + '/roles/' + snowflake(roleId, 'Role ID'), options);
|
|
147
|
+
}
|
|
148
|
+
vanityUrl(guildId, options) {
|
|
149
|
+
return this.rest.request('GET', guildPath(guildId) + '/vanity-url', options);
|
|
150
|
+
}
|
|
151
|
+
editVanityUrl(guildId, code, options) {
|
|
152
|
+
if (code !== null && (code.length > 32 || !/^[A-Za-z0-9][A-Za-z0-9 -]*[A-Za-z0-9]$/.test(code))) {
|
|
153
|
+
throw new TypeError('A custom invite code takes 2 to 32 letters, digits, spaces or inner hyphens');
|
|
154
|
+
}
|
|
155
|
+
return this.rest.request('PATCH', guildPath(guildId) + '/vanity-url', { ...options, body: { code } });
|
|
156
|
+
}
|
|
157
|
+
editCurrentMember(guildId, edit, options) {
|
|
158
|
+
return this.rest.request('PATCH', guildPath(guildId) + '/members/@me', { ...options, body: edit });
|
|
159
|
+
}
|
|
160
|
+
setNickname(guildId, nick, options) {
|
|
161
|
+
if (nick !== null && ([...nick].length < 1 || [...nick].length > 32))
|
|
162
|
+
throw new RangeError('A nickname takes 1 to 32 characters');
|
|
163
|
+
return this.editCurrentMember(guildId, { nick }, options);
|
|
164
|
+
}
|
|
165
|
+
findMembers(guildId, query, { limit = 1, signal } = {}) {
|
|
166
|
+
if (typeof query !== 'string' || [...query].length > 100 || !Number.isSafeInteger(limit) || limit < 1 || limit > 1000) {
|
|
167
|
+
throw new RangeError('A name search takes a query of up to 100 characters and a limit of 1 to 1000');
|
|
168
|
+
}
|
|
169
|
+
return this.rest.request('GET', guildPath(guildId) + '/members/search', {
|
|
170
|
+
query: new URLSearchParams({ query, limit: String(limit) }), signal,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
transferOwnership(guildId, newOwnerId, { signal, reason, ...proof } = {}) {
|
|
174
|
+
return this.rest.request('POST', guildPath(guildId) + '/transfer-ownership', {
|
|
175
|
+
signal, reason, body: { new_owner_id: snowflake(newOwnerId, 'New owner ID'), ...proof },
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
deleteOwnMessages(guildId, { signal, ...proof } = {}) {
|
|
179
|
+
return this.rest.request('POST', '/users/@me' + guildPath(guildId) + '/messages/bulk-delete-mine', { signal, body: proof });
|
|
180
|
+
}
|
|
181
|
+
async *iterateMembers(guildId, { signal } = {}) {
|
|
182
|
+
let after;
|
|
183
|
+
while (true) {
|
|
184
|
+
const page = await this.members(guildId, { limit: 1000, after, signal });
|
|
185
|
+
let next = after;
|
|
186
|
+
for (const member of page) {
|
|
187
|
+
yield member;
|
|
188
|
+
next = member.user?.id ?? next;
|
|
189
|
+
}
|
|
190
|
+
if (page.length < 1000 || next === after)
|
|
191
|
+
return;
|
|
192
|
+
after = next;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async *iterateAuditLog(guildId, { userId, actionType, signal } = {}) {
|
|
196
|
+
let before;
|
|
197
|
+
while (true) {
|
|
198
|
+
const query = new URLSearchParams({ limit: '100' });
|
|
199
|
+
if (before !== undefined)
|
|
200
|
+
query.set('before', before);
|
|
201
|
+
if (userId !== undefined)
|
|
202
|
+
query.set('user_id', snowflake(userId, 'User ID'));
|
|
203
|
+
if (actionType !== undefined)
|
|
204
|
+
query.set('action_type', String(actionType));
|
|
205
|
+
const page = await this.auditLog(guildId, query, { signal });
|
|
206
|
+
for (const entry of page.audit_log_entries)
|
|
207
|
+
yield entry;
|
|
208
|
+
const last = page.audit_log_entries.at(-1)?.id;
|
|
209
|
+
if (page.audit_log_entries.length < 100 || !last || last === before)
|
|
210
|
+
return;
|
|
211
|
+
before = last;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
87
214
|
auditLog(guildId, query, options) {
|
|
88
215
|
return this.rest.request('GET', guildPath(guildId) + '/audit-logs', { ...options, query });
|
|
89
216
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function tokenId(token: string): string | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const digits = /^\d+$/;
|
|
2
|
+
const base64 = /^[A-Za-z0-9+/_-]+={0,2}$/;
|
|
3
|
+
export function tokenId(token) {
|
|
4
|
+
if (typeof token !== 'string' || !token.includes('.'))
|
|
5
|
+
return undefined;
|
|
6
|
+
const head = token.slice(0, token.indexOf('.'));
|
|
7
|
+
if (!head)
|
|
8
|
+
return undefined;
|
|
9
|
+
if (base64.test(head)) {
|
|
10
|
+
const decoded = Buffer.from(head.replace(/-/g, '+').replace(/_/g, '/'), 'base64').toString('latin1');
|
|
11
|
+
if (decoded && digits.test(decoded))
|
|
12
|
+
return decoded;
|
|
13
|
+
}
|
|
14
|
+
return digits.test(head) ? head : undefined;
|
|
15
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type CommandChoice, type MicupInteraction } from '../model/interaction.js';
|
|
2
|
-
import type { MicupMessage } from '
|
|
2
|
+
import type { MicupMessage } from '../model/entities.js';
|
|
3
3
|
import { type MessageInput } from './messages.js';
|
|
4
4
|
import type { MicupRequestOptions, RestTransport } from './transport.js';
|
|
5
5
|
export interface InteractionReplyOptions extends MicupRequestOptions {
|
package/dist/rest/messages.d.ts
CHANGED
|
@@ -1,34 +1,13 @@
|
|
|
1
|
+
import { type MicupEmbed } from '../model/embed.js';
|
|
2
|
+
export type { MicupEmbed } from '../model/embed.js';
|
|
3
|
+
import type { MessageReference } from '../model/entities.js';
|
|
4
|
+
import type { UploadedAttachment } from './attachments.js';
|
|
1
5
|
export interface MicupFile {
|
|
2
6
|
name: string;
|
|
3
7
|
data: Blob;
|
|
4
8
|
description?: string;
|
|
5
|
-
}
|
|
6
|
-
export interface MicupEmbed {
|
|
7
9
|
title?: string;
|
|
8
|
-
|
|
9
|
-
url?: string;
|
|
10
|
-
color?: number;
|
|
11
|
-
timestamp?: string;
|
|
12
|
-
fields?: readonly {
|
|
13
|
-
name: string;
|
|
14
|
-
value: string;
|
|
15
|
-
inline?: boolean;
|
|
16
|
-
}[];
|
|
17
|
-
image?: {
|
|
18
|
-
url: string;
|
|
19
|
-
};
|
|
20
|
-
thumbnail?: {
|
|
21
|
-
url: string;
|
|
22
|
-
};
|
|
23
|
-
footer?: {
|
|
24
|
-
text: string;
|
|
25
|
-
icon_url?: string;
|
|
26
|
-
};
|
|
27
|
-
author?: {
|
|
28
|
-
name: string;
|
|
29
|
-
url?: string;
|
|
30
|
-
icon_url?: string;
|
|
31
|
-
};
|
|
10
|
+
spoiler?: boolean;
|
|
32
11
|
}
|
|
33
12
|
export interface AllowedMentions {
|
|
34
13
|
parse?: readonly ('users' | 'roles' | 'everyone')[];
|
|
@@ -43,6 +22,11 @@ export interface MessageInput {
|
|
|
43
22
|
allowed_mentions?: AllowedMentions;
|
|
44
23
|
flags?: number;
|
|
45
24
|
files?: readonly MicupFile[];
|
|
25
|
+
uploads?: readonly UploadedAttachment[];
|
|
26
|
+
nonce?: string;
|
|
27
|
+
enforce_nonce?: boolean;
|
|
28
|
+
tts?: boolean;
|
|
29
|
+
sticker_ids?: readonly string[];
|
|
46
30
|
attachments?: readonly {
|
|
47
31
|
id: string;
|
|
48
32
|
filename?: string;
|
|
@@ -58,8 +42,48 @@ export interface ListMessageOptions {
|
|
|
58
42
|
}
|
|
59
43
|
export declare function snowflake(id: string, label: string): string;
|
|
60
44
|
export declare function messagesPath(channelId: string, messageId?: string): string;
|
|
61
|
-
export declare function
|
|
62
|
-
|
|
63
|
-
channel_id: string;
|
|
64
|
-
}): object;
|
|
45
|
+
export declare function assertFileName(name: string): void;
|
|
46
|
+
export declare function messageBody({ files, uploads, ...message }: MessageInput, reference?: MessageReference, extra?: object): object;
|
|
65
47
|
export declare function messageQuery({ before, after, around, limit }: ListMessageOptions): URLSearchParams;
|
|
48
|
+
export interface MessageForward {
|
|
49
|
+
channel_id: string;
|
|
50
|
+
message_id: string;
|
|
51
|
+
guild_id?: string;
|
|
52
|
+
attachment_ids?: readonly string[];
|
|
53
|
+
embed_indices?: readonly number[];
|
|
54
|
+
}
|
|
55
|
+
export interface MessageSearch {
|
|
56
|
+
context_guild_id?: string;
|
|
57
|
+
context_channel_id?: string;
|
|
58
|
+
content?: string;
|
|
59
|
+
min_id?: string;
|
|
60
|
+
max_id?: string;
|
|
61
|
+
channel_ids?: readonly string[];
|
|
62
|
+
exclude_channel_id?: readonly string[];
|
|
63
|
+
exact_phrases?: readonly string[];
|
|
64
|
+
author_id?: readonly string[];
|
|
65
|
+
exclude_author_id?: readonly string[];
|
|
66
|
+
author_type?: readonly ('user' | 'bot' | 'webhook')[];
|
|
67
|
+
mentions?: readonly string[];
|
|
68
|
+
has?: readonly string[];
|
|
69
|
+
exclude_has?: readonly string[];
|
|
70
|
+
link_hostname?: readonly string[];
|
|
71
|
+
attachment_filename?: readonly string[];
|
|
72
|
+
attachment_extension?: readonly string[];
|
|
73
|
+
mention_everyone?: boolean;
|
|
74
|
+
pinned?: boolean;
|
|
75
|
+
include_nsfw?: boolean;
|
|
76
|
+
hits_per_page?: number;
|
|
77
|
+
page?: number;
|
|
78
|
+
sort_by?: 'timestamp' | 'relevance';
|
|
79
|
+
sort_order?: 'asc' | 'desc';
|
|
80
|
+
}
|
|
81
|
+
export interface MessageSearchResult {
|
|
82
|
+
messages: import('../model/entities.js').MicupMessage[];
|
|
83
|
+
channels?: import('../model/guild.js').MicupChannel[];
|
|
84
|
+
threads?: import('../model/guild.js').MicupChannel[];
|
|
85
|
+
total: number;
|
|
86
|
+
hits_per_page: number;
|
|
87
|
+
page: number;
|
|
88
|
+
indexing?: boolean;
|
|
89
|
+
}
|