snowtransfer 0.15.0 → 0.16.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.
- package/dist/index.d.ts +181 -132
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
1
|
+
import EventEmitter, { EventEmitter as EventEmitter$1 } from 'events';
|
|
2
2
|
import { RESTGetAPIAuditLogQuery, RESTGetAPIAuditLogResult, RESTGetAPIAutoModerationRulesResult, RESTGetAPIAutoModerationRuleResult, RESTPostAPIAutoModerationRuleJSONBody, RESTPostAPIAutoModerationRuleResult, RESTPatchAPIAutoModerationRuleJSONBody, RESTPatchAPIAutoModerationRuleResult, RESTDeleteAPIAutoModerationRuleResult, RESTGetAPIGatewayResult, RESTGetAPIGatewayBotResult, APIApplication, RESTPatchCurrentApplicationJSONBody, RESTGetAPIGuildEmojisResult, RESTGetAPIGuildEmojiResult, RESTPostAPIGuildEmojiJSONBody, RESTPostAPIGuildEmojiResult, RESTPatchAPIGuildEmojiJSONBody, RESTPatchAPIGuildEmojiResult, RESTDeleteAPIGuildEmojiResult, RESTGetAPIStickerResult, RESTGetAPIGuildStickersResult, RESTGetAPIGuildStickerResult, RESTPostAPIGuildStickerFormDataBody, RESTPostAPIGuildStickerResult, RESTPatchAPIGuildStickerJSONBody, RESTPatchAPIGuildStickerResult, RESTDeleteAPIGuildStickerResult, RESTGetAPIApplicationEmojisResult, RESTGetAPIApplicationEmojiResult, RESTPostAPIApplicationEmojiJSONBody, RESTPostAPIApplicationEmojiResult, RESTPatchAPIApplicationEmojiJSONBody, RESTPatchAPIApplicationEmojiResult, RESTDeleteAPIApplicationEmojiResult, RESTGetAPIEntitlementsResult, RESTGetAPIEntitlementResult, RESTPostAPIEntitlementConsumeResult, RESTPostAPIEntitlementJSONBody, RESTPostAPIEntitlementResult, RESTDeleteAPIEntitlementResult, RESTGetAPIGuildResult, RESTGetAPIGuildPreviewResult, RESTPatchAPIGuildJSONBody, RESTPatchAPIGuildResult, RESTGetAPIGuildChannelsResult, RESTPostAPIGuildChannelJSONBody, RESTPostAPIGuildChannelResult, RESTPatchAPIGuildChannelPositionsJSONBody, RESTPatchAPIGuildChannelPositionsResult, RESTGetAPIGuildThreadsResult, RESTGetAPIGuildMemberResult, RESTGetAPIGuildMembersQuery, RESTGetAPIGuildMembersResult, RESTGetAPIGuildMembersSearchQuery, RESTGetAPIGuildMembersSearchResult, RESTPutAPIGuildMemberJSONBody, RESTPutAPIGuildMemberResult, RESTPatchAPIGuildMemberJSONBody, RESTPatchAPIGuildMemberResult, RESTPatchAPICurrentGuildMemberJSONBody, APIGuildMember, RESTPutAPIGuildMemberRoleResult, RESTDeleteAPIGuildMemberRoleResult, RESTDeleteAPIGuildMemberResult, RESTGetAPIGuildBansQuery, RESTGetAPIGuildBansResult, RESTGetAPIGuildBanResult, RESTPutAPIGuildBanJSONBody, RESTPutAPIGuildBanResult, RESTDeleteAPIGuildBanResult, RESTGetAPIGuildRolesResult, RESTPostAPIGuildRoleJSONBody, RESTPostAPIGuildRoleResult, RESTPatchAPIGuildRolePositionsJSONBody, RESTPatchAPIGuildRolePositionsResult, RESTPatchAPIGuildRoleJSONBody, RESTPatchAPIGuildRoleResult, RESTDeleteAPIGuildRoleResult, RESTGetAPIGuildPruneCountQuery, RESTGetAPIGuildPruneCountResult, RESTPostAPIGuildPruneJSONBody, RESTPostAPIGuildPruneResult, RESTGetAPIGuildVoiceRegionsResult, RESTGetAPIGuildInvitesResult, RESTGetAPIGuildIntegrationsResult, RESTDeleteAPIGuildIntegrationResult, RESTGetAPIGuildWidgetSettingsResult, RESTPatchAPIGuildWidgetSettingsJSONBody, RESTPatchAPIGuildWidgetSettingsResult, APIGuildWidget, RESTGetAPIGuildVanityUrlResult, RESTGetAPIGuildWelcomeScreenResult, RESTPatchAPIGuildWelcomeScreenJSONBody, RESTPatchAPIGuildWelcomeScreenResult, RESTPatchAPIGuildVoiceStateCurrentMemberJSONBody, RESTPatchAPIGuildVoiceStateCurrentMemberResult, RESTPatchAPIGuildVoiceStateUserJSONBody, RESTPatchAPIGuildVoiceStateUserResult, RESTGetAPIGuildScheduledEventsResult, RESTPostAPIGuildScheduledEventJSONBody, RESTPostAPIGuildScheduledEventResult, RESTGetAPIGuildScheduledEventResult, RESTPatchAPIGuildScheduledEventJSONBody, RESTPatchAPIGuildScheduledEventResult, RESTDeleteAPIGuildScheduledEventResult, RESTGetAPIGuildScheduledEventUsersQuery, RESTGetAPIGuildScheduledEventUsersResult, RESTGetAPITemplateResult, RESTGetAPIGuildTemplatesResult, RESTPostAPIGuildTemplatesJSONBody, RESTPostAPIGuildTemplatesResult, RESTPutAPIGuildTemplateSyncResult, RESTPatchAPIGuildTemplateJSONBody, RESTPatchAPIGuildTemplateResult, RESTDeleteAPIGuildTemplateResult, RESTPostAPIChannelWebhookJSONBody, RESTPostAPIChannelWebhookResult, RESTGetAPIChannelWebhooksResult, RESTGetAPIGuildWebhooksResult, RESTGetAPIWebhookResult, RESTPatchAPIWebhookWithTokenJSONBody, RESTPatchAPIWebhookWithTokenResult, RESTPatchAPIWebhookJSONBody, RESTPatchAPIWebhookResult, RESTDeleteAPIWebhookResult, RESTPostAPIWebhookWithTokenJSONBody, RESTPostAPIWebhookWithTokenQuery, RESTPostAPIWebhookWithTokenResult, RESTPostAPIWebhookWithTokenWaitResult, RESTPostAPIWebhookWithTokenSlackQuery, RESTPostAPIWebhookWithTokenSlackResult, RESTPostAPIWebhookWithTokenSlackWaitResult, RESTPostAPIWebhookWithTokenGitHubQuery, RESTPostAPIWebhookWithTokenGitHubResult, RESTPostAPIWebhookWithTokenGitHubWaitResult, RESTGetAPIWebhookWithTokenMessageResult, RESTPatchAPIWebhookWithTokenMessageJSONBody, RESTPatchAPIWebhookWithTokenMessageResult, RESTDeleteAPIWebhookWithTokenMessageResult, RESTGetAPIApplicationCommandsResult, RESTPostAPIApplicationCommandsJSONBody, RESTPostAPIApplicationCommandsResult, RESTGetAPIApplicationCommandResult, RESTPatchAPIApplicationCommandJSONBody, RESTPatchAPIApplicationCommandResult, RESTPutAPIApplicationCommandsJSONBody, RESTPutAPIApplicationCommandsResult, RESTGetAPIApplicationGuildCommandsResult, RESTPostAPIApplicationGuildCommandsJSONBody, RESTPostAPIApplicationGuildCommandsResult, RESTGetAPIApplicationGuildCommandResult, RESTPatchAPIApplicationGuildCommandJSONBody, RESTPatchAPIApplicationGuildCommandResult, RESTPutAPIApplicationGuildCommandsJSONBody, RESTPutAPIApplicationGuildCommandsResult, RESTGetAPIApplicationCommandPermissionsResult, RESTPutAPIApplicationCommandPermissionsJSONBody, RESTPutAPIApplicationCommandPermissionsResult, RESTPostAPIInteractionCallbackJSONBody, RESTGetAPIInteractionOriginalResponseResult, RESTPatchAPIInteractionOriginalResponseJSONBody, RESTPatchAPIInteractionOriginalResponseResult, RESTDeleteAPIInteractionOriginalResponseResult, RESTPostAPIInteractionFollowupJSONBody, RESTPostAPIInteractionFollowupResult, RESTGetAPIInteractionFollowupResult, RESTPatchAPIInteractionFollowupJSONBody, RESTPatchAPIInteractionFollowupResult, RESTDeleteAPIInteractionFollowupResult, RESTGetAPIInviteQuery, RESTGetAPIInviteResult, RESTDeleteAPIInviteResult, RESTGetAPISKUsResult, RESTGetAPISKUSubscriptionsQuery, RESTGetAPISKUSubscriptionsResult, RESTGetAPISKUSubscriptionResult, RESTPostAPIStageInstanceJSONBody, RESTPostAPIStageInstanceResult, RESTGetAPIStageInstanceResult, RESTPatchAPIStageInstanceJSONBody, RESTPatchAPIStageInstanceResult, RESTDeleteAPIStageInstanceResult, RESTGetAPICurrentUserResult, RESTGetAPIUserResult, RESTPatchAPICurrentUserJSONBody, RESTPatchAPICurrentUserResult, RESTGetAPICurrentUserGuildsQuery, RESTGetAPICurrentUserGuildsResult, RESTDeleteAPICurrentUserGuildResult, RESTPostAPICurrentUserCreateDMChannelResult, RESTGetAPICurrentUserConnectionsResult, RESTGetAPICurrentUserApplicationRoleConnectionResult, RESTPutAPICurrentUserApplicationRoleConnectionJSONBody, RESTPutAPICurrentUserApplicationRoleConnectionResult, RESTGetAPIVoiceRegionsResult, APIVoiceState, APIAllowedMentions, RESTGetAPIChannelResult, RESTPatchAPIChannelJSONBody, RESTPatchAPIChannelResult, APIThreadChannel, RESTDeleteAPIChannelResult, RESTGetAPIChannelMessagesQuery, RESTGetAPIChannelMessagesResult, RESTGetAPIChannelMessageResult, RESTPostAPIChannelMessageJSONBody, RESTPostAPIChannelMessageResult, RESTPostAPIChannelMessageCrosspostResult, RESTPutAPIChannelMessageReactionResult, RESTDeleteAPIChannelMessageUserReactionResult, RESTDeleteAPIChannelMessageReactionResult, RESTGetAPIChannelMessageReactionUsersQuery, RESTGetAPIChannelMessageReactionUsersResult, RESTDeleteAPIChannelAllMessageReactionsResult, RESTPatchAPIChannelMessageJSONBody, RESTPatchAPIChannelMessageResult, RESTDeleteAPIChannelMessageResult, RESTPostAPIChannelMessagesBulkDeleteResult, RESTPutAPIChannelPermissionJSONBody, RESTPutAPIChannelPermissionResult, RESTGetAPIChannelInvitesResult, RESTPostAPIChannelInviteJSONBody, RESTPostAPIChannelInviteResult, RESTDeleteAPIChannelPermissionResult, RESTPostAPIChannelFollowersResult, RESTPostAPIChannelTypingResult, RESTGetAPIChannelMessagesPinsQuery, RESTGetAPIChannelMessagesPinsResult, RESTPutAPIChannelMessagesPinResult, RESTDeleteAPIChannelMessagesPinResult, RESTPostAPIChannelMessagesThreadsJSONBody, RESTPostAPIChannelMessagesThreadsResult, RESTPostAPIChannelThreadsJSONBody, APITextBasedChannel, ChannelType, RESTPutAPIChannelThreadMembersResult, RESTDeleteAPIChannelThreadMembersResult, RESTGetAPIChannelThreadMemberResult, RESTGetAPIChannelThreadMembersQuery, RESTGetAPIChannelThreadMembersResult, RESTGetAPIChannelThreadsArchivedQuery, RESTGetAPIChannelThreadsArchivedPublicResult, RESTGetAPIChannelThreadsArchivedPrivateResult, RESTGetAPIChannelUsersThreadsArchivedResult, RESTGetAPIPollAnswerVotersQuery, RESTGetAPIPollAnswerVotersResult, RESTPostAPIPollExpireResult, RESTPostOAuth2AccessTokenResult, APIMessageTopLevelComponent } from 'discord-api-types/v10';
|
|
3
3
|
import { Blob, File as File$1 } from 'buffer';
|
|
4
4
|
import { Readable } from 'stream';
|
|
@@ -17,42 +17,127 @@ type RatelimitInfo = {
|
|
|
17
17
|
global: boolean;
|
|
18
18
|
code?: number;
|
|
19
19
|
};
|
|
20
|
+
type RequestEventData = {
|
|
21
|
+
endpoint: string;
|
|
22
|
+
method: string;
|
|
23
|
+
dataType: "json" | "multipart";
|
|
24
|
+
data: any;
|
|
25
|
+
};
|
|
26
|
+
type HandlerEvents = {
|
|
27
|
+
request: [string, RequestEventData];
|
|
28
|
+
done: [string, Response, RequestEventData];
|
|
29
|
+
requestError: [string, Error];
|
|
30
|
+
rateLimit: [{
|
|
31
|
+
timeout: number;
|
|
32
|
+
remaining: number;
|
|
33
|
+
limit: number;
|
|
34
|
+
method: string;
|
|
35
|
+
path: string;
|
|
36
|
+
route: string;
|
|
37
|
+
}];
|
|
38
|
+
};
|
|
39
|
+
type SMState = {
|
|
40
|
+
onEnter: Array<(event: string) => unknown>;
|
|
41
|
+
onLeave: Array<(event: string) => unknown>;
|
|
42
|
+
transitions: Map<string, SMTransition>;
|
|
43
|
+
};
|
|
44
|
+
type SMTransition = {
|
|
45
|
+
destination: string;
|
|
46
|
+
onTransition?: Array<(...args: any[]) => unknown>;
|
|
47
|
+
};
|
|
48
|
+
type SMHistory = {
|
|
49
|
+
from: string;
|
|
50
|
+
event: string;
|
|
51
|
+
to: string;
|
|
52
|
+
time: number;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
interface StateMachineEvents {
|
|
56
|
+
enter: [string];
|
|
57
|
+
}
|
|
20
58
|
/**
|
|
21
|
-
*
|
|
22
|
-
* @since 0.
|
|
59
|
+
* Class used to define states code is expected to be in and transitions to other states and code to run during those transitions and states
|
|
60
|
+
* @since 0.16.0
|
|
23
61
|
*/
|
|
24
|
-
|
|
62
|
+
declare class StateMachine extends EventEmitter<StateMachineEvents> {
|
|
63
|
+
currentStateName: string;
|
|
64
|
+
readonly states: Map<string, SMState>;
|
|
65
|
+
private editable;
|
|
66
|
+
private readonly deferredTransitionCreators;
|
|
67
|
+
private readonly history;
|
|
25
68
|
/**
|
|
26
|
-
*
|
|
69
|
+
* Create a new StateMachine
|
|
70
|
+
* @param currentStateName The state this state machine is currently in. When constructing the StateMachine, this is the entry state.
|
|
27
71
|
*/
|
|
28
|
-
|
|
72
|
+
constructor(currentStateName: string);
|
|
29
73
|
/**
|
|
30
|
-
*
|
|
74
|
+
* Helper function that throws an Error when something tries to edit the state machine after it has been frozen/finalized.
|
|
75
|
+
* @since 0.16.0
|
|
31
76
|
*/
|
|
32
|
-
|
|
77
|
+
guardEditable(): void;
|
|
33
78
|
/**
|
|
34
|
-
*
|
|
79
|
+
* Helper function that throws an Error when something tries to use the state machine before it has been frozen/finalized.
|
|
80
|
+
* @since 0.16.0
|
|
35
81
|
*/
|
|
36
|
-
|
|
82
|
+
guardNotEditable(): void;
|
|
37
83
|
/**
|
|
38
|
-
*
|
|
39
|
-
* @since 0.
|
|
40
|
-
* @param
|
|
41
|
-
* @
|
|
84
|
+
* Define a state in the state machine.
|
|
85
|
+
* @since 0.16.0
|
|
86
|
+
* @param name The name of the state.
|
|
87
|
+
* @param cbs Callbacks for points during transitions relating to this state as well as transitions to other states.
|
|
42
88
|
*/
|
|
43
|
-
|
|
89
|
+
defineState(name: string, cbs?: {
|
|
90
|
+
onEnter: SMState["onEnter"];
|
|
91
|
+
onLeave: SMState["onLeave"];
|
|
92
|
+
transitions: Map<string, SMTransition>;
|
|
93
|
+
}): this;
|
|
44
94
|
/**
|
|
45
|
-
*
|
|
46
|
-
* @since 0.
|
|
47
|
-
* @param
|
|
95
|
+
* Define a transition between 2 states in the state machine.
|
|
96
|
+
* @since 0.16.0
|
|
97
|
+
* @param from The name of the state this transition would come from.
|
|
98
|
+
* @param event The event that can trigger this transition.
|
|
99
|
+
* @param to The name of the state this transition would go to.
|
|
100
|
+
* @param cb A callback to run when this transition occurs.
|
|
48
101
|
*/
|
|
49
|
-
|
|
102
|
+
defineTransition(from: string, event: string, to: string, cb?: (...args: any[]) => unknown): this;
|
|
50
103
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
104
|
+
* Define a transition from every state to another state in the state machine.
|
|
105
|
+
* @since 0.16.0
|
|
106
|
+
* @param event The event that can trigger this transition.
|
|
107
|
+
* @param to The name of the state this transition would go to.
|
|
108
|
+
*/
|
|
109
|
+
defineUniversalTransition(event: string, to: string): this;
|
|
110
|
+
/**
|
|
111
|
+
* Finalize the state machine, making its states and transitions now readonly and usable.
|
|
112
|
+
* @since 0.16.0
|
|
113
|
+
*/
|
|
114
|
+
freeze(): void;
|
|
115
|
+
/**
|
|
116
|
+
* Trigger an event to do a transition from the current state to another as defined previously.
|
|
117
|
+
*
|
|
118
|
+
* Will throw an Error if there is no transition from the current state to another based off the event.
|
|
119
|
+
* @since 0.16.0
|
|
120
|
+
* @param event The event that occured.
|
|
121
|
+
* @param args Arguments to pass to the callback of the transition's onTransition functions if any.
|
|
53
122
|
*/
|
|
54
|
-
|
|
123
|
+
doTransition(event: string, ...args: any[]): void;
|
|
124
|
+
/**
|
|
125
|
+
* Trigger an event to do a transition from the current state to another as defined previously at a later point in time.
|
|
126
|
+
*
|
|
127
|
+
* Will throw an Error if there is no transition from the current state to another based off the event.
|
|
128
|
+
* @since 0.16.0
|
|
129
|
+
* @param event The event that occured.
|
|
130
|
+
* @param delayMs The time in milliseconds this transition will run in.
|
|
131
|
+
* @param args Arguments to pass to the callback of the transition's onTransition functions if any.
|
|
132
|
+
*/
|
|
133
|
+
doTransitionLater(event: string, delayMs: number, ...args: Array<any>): void;
|
|
134
|
+
/**
|
|
135
|
+
* Print debug info about this state machine to stdout in the form of a table.
|
|
136
|
+
* @since 0.16.0
|
|
137
|
+
*/
|
|
138
|
+
debug(): void;
|
|
55
139
|
}
|
|
140
|
+
|
|
56
141
|
/**
|
|
57
142
|
* @since 0.3.0
|
|
58
143
|
*/
|
|
@@ -69,111 +154,65 @@ declare class DiscordAPIError extends Error {
|
|
|
69
154
|
}, request: RequestEventData, response: Response);
|
|
70
155
|
}
|
|
71
156
|
/**
|
|
72
|
-
*
|
|
73
|
-
* @since 0.12.0
|
|
74
|
-
* @protected
|
|
75
|
-
*/
|
|
76
|
-
declare class AsyncSequentialQueue implements Queue {
|
|
77
|
-
calls: Array<() => any>;
|
|
78
|
-
private _blocked;
|
|
79
|
-
private _running;
|
|
80
|
-
get blocked(): boolean;
|
|
81
|
-
get running(): boolean;
|
|
82
|
-
enqueue<T>(fn: () => T): Promise<T>;
|
|
83
|
-
setBlocked(blocked: boolean): void;
|
|
84
|
-
drop(): void;
|
|
85
|
-
private _tryRun;
|
|
86
|
-
private _next;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Ratelimiter used for handling the ratelimits imposed by the rest api
|
|
90
|
-
* @since 0.1.0
|
|
91
|
-
* @protected
|
|
157
|
+
* @since 0.16.0
|
|
92
158
|
*/
|
|
93
|
-
declare class
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
* A Map of Buckets keyed by route keys that store rate limit info
|
|
97
|
-
*/
|
|
98
|
-
buckets: Map<string, InstanceType<B>>;
|
|
99
|
-
/**
|
|
100
|
-
* The bucket that limits how many requests per second you can make globally
|
|
101
|
-
*/
|
|
102
|
-
globalBucket: LocalBucket;
|
|
103
|
-
/**
|
|
104
|
-
* If you're being globally rate limited
|
|
105
|
-
*/
|
|
106
|
-
get global(): boolean;
|
|
159
|
+
declare class Counter {
|
|
160
|
+
limit: number;
|
|
161
|
+
reset: number;
|
|
107
162
|
/**
|
|
108
|
-
*
|
|
109
|
-
* @param BucketConstructor The constructor function to call new on when creating buckets to cache and use
|
|
163
|
+
* Remaining amount of executions during the current timeframe
|
|
110
164
|
*/
|
|
111
|
-
|
|
165
|
+
remaining: number;
|
|
166
|
+
private firstRequestTime;
|
|
167
|
+
private resetAt;
|
|
112
168
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* @
|
|
116
|
-
* @param url url to reduce to a key something like /channels/266277541646434305/messages/266277541646434305/
|
|
117
|
-
* @param method method of the request, usual http methods like get, etc.
|
|
118
|
-
* @returns reduced url: /channels/266277541646434305/messages/:id/
|
|
169
|
+
* Create a new base bucket
|
|
170
|
+
* @param limit Number of functions that may be executed during the timeframe set in reset
|
|
171
|
+
* @param reset Timeframe in milliseconds until the ratelimit resets after first
|
|
119
172
|
*/
|
|
120
|
-
|
|
173
|
+
constructor(limit: number, reset: number);
|
|
174
|
+
private checkReset;
|
|
121
175
|
/**
|
|
122
|
-
*
|
|
123
|
-
* @since 0.1.0
|
|
124
|
-
* @param fn function to call once the ratelimit is ready
|
|
125
|
-
* @param url Endpoint of the request
|
|
126
|
-
* @param method Http method used by the request
|
|
176
|
+
* Like new.
|
|
127
177
|
*/
|
|
128
|
-
|
|
178
|
+
hasReset(): boolean;
|
|
129
179
|
/**
|
|
130
|
-
*
|
|
131
|
-
* @param ms How long in milliseconds this Ratelimiter is globally ratelimited for
|
|
180
|
+
* Returns true only if the caller is allowed to call take() and then send the request.
|
|
132
181
|
*/
|
|
133
|
-
|
|
182
|
+
canTake(): boolean;
|
|
183
|
+
take(): boolean;
|
|
184
|
+
timeUntilReset(): number;
|
|
185
|
+
applyCount(limit: number, remaining: number, resetAfter: number): void;
|
|
134
186
|
}
|
|
135
187
|
/**
|
|
136
188
|
* Bucket used for saving ratelimits
|
|
137
189
|
* @since 0.1.0
|
|
138
190
|
* @protected
|
|
139
191
|
*/
|
|
140
|
-
declare class
|
|
192
|
+
declare class Bucket {
|
|
141
193
|
limit: number;
|
|
142
194
|
reset: number;
|
|
143
|
-
/**
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
*/
|
|
150
|
-
remaining: number;
|
|
151
|
-
private resetTimeout;
|
|
195
|
+
/** Tracks the state this bucket is in (blocked, running, waiting, etc) and what operations are allowed. */
|
|
196
|
+
sm: StateMachine;
|
|
197
|
+
/** Wrapped functions which always resolve (not reject) after the original function has completed and resolved. The original function may manipulate rate limit buckets in that time before it resolves. */
|
|
198
|
+
calls: Array<() => any>;
|
|
199
|
+
counters: Array<Counter>;
|
|
200
|
+
private pauseRequested;
|
|
152
201
|
/**
|
|
153
202
|
* Create a new base bucket
|
|
154
203
|
* @param limit Number of functions that may be executed during the timeframe set in reset
|
|
155
204
|
* @param reset Timeframe in milliseconds until the ratelimit resets after first
|
|
156
|
-
* @param remaining Remaining amount of executions during the current timeframe
|
|
157
205
|
*/
|
|
158
|
-
constructor(limit?: number, reset?: number,
|
|
206
|
+
constructor(limit?: number, reset?: number, additionalCounters?: Array<Counter>);
|
|
159
207
|
/**
|
|
160
208
|
* Queue a function to be executed
|
|
161
209
|
* @since 0.12.0
|
|
162
210
|
* @param fn function to be executed
|
|
163
211
|
* @returns Result of the function if any
|
|
164
212
|
*/
|
|
165
|
-
enqueue<T>(fn: (bkt: this) => T): Promise<T>;
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
* @since 0.8.3
|
|
169
|
-
* @param ms Timeframe in milliseconds until the ratelimit resets after
|
|
170
|
-
*/
|
|
171
|
-
makeResetTimeout(ms: number): void;
|
|
172
|
-
/**
|
|
173
|
-
* Reset the remaining tokens to the base limit
|
|
174
|
-
* @since 0.1.0
|
|
175
|
-
*/
|
|
176
|
-
resetRemaining(): void;
|
|
213
|
+
enqueue<T>(fn: (bkt: this) => Promise<T>): Promise<T>;
|
|
214
|
+
pause(): void;
|
|
215
|
+
resume(): void;
|
|
177
216
|
/**
|
|
178
217
|
* Clear the current queue of events to be sent
|
|
179
218
|
* @since 0.1.0
|
|
@@ -181,49 +220,52 @@ declare class LocalBucket {
|
|
|
181
220
|
dropQueue(): void;
|
|
182
221
|
}
|
|
183
222
|
/**
|
|
184
|
-
*
|
|
185
|
-
* @since 0.
|
|
223
|
+
* Ratelimiter used for handling the ratelimits imposed by the rest api
|
|
224
|
+
* @since 0.1.0
|
|
186
225
|
* @protected
|
|
187
226
|
*/
|
|
188
|
-
declare class
|
|
189
|
-
readonly ratelimiter: Ratelimiter;
|
|
190
|
-
readonly routeKey: string;
|
|
227
|
+
declare class Ratelimiter {
|
|
191
228
|
/**
|
|
192
|
-
*
|
|
193
|
-
* @param ratelimiter ratelimiter used for ratelimiting requests. Assigned by ratelimiter
|
|
194
|
-
* @param routeKey Key used internally to routify requests. Assigned by ratelimiter
|
|
229
|
+
* A Map of Buckets keyed by route keys that store rate limit info
|
|
195
230
|
*/
|
|
196
|
-
|
|
231
|
+
buckets: Map<string, Bucket>;
|
|
197
232
|
/**
|
|
198
|
-
*
|
|
199
|
-
|
|
233
|
+
* The bucket that limits how many requests per second you can make globally
|
|
234
|
+
*/
|
|
235
|
+
globalBucket: Bucket;
|
|
236
|
+
/**
|
|
237
|
+
* If you're being globally rate limited
|
|
238
|
+
*/
|
|
239
|
+
get global(): boolean;
|
|
240
|
+
constructor();
|
|
241
|
+
/**
|
|
242
|
+
* Returns a key for saving ratelimits for routes
|
|
243
|
+
* (Taken from https://github.com/abalabahaha/eris/blob/master/lib/rest/RequestHandler.js) -> I luv u abal <3
|
|
244
|
+
* @since 0.1.0
|
|
245
|
+
* @param url url to reduce to a key something like /channels/266277541646434305/messages/266277541646434305/
|
|
246
|
+
* @param method method of the request, usual http methods like get, etc.
|
|
247
|
+
* @returns reduced url: /channels/266277541646434305/messages/:id/
|
|
248
|
+
*/
|
|
249
|
+
routify(url: string, method: string): string;
|
|
250
|
+
/**
|
|
251
|
+
* Choose a bucket from the route and enqueue a rest call in it
|
|
252
|
+
* @since 0.1.0
|
|
253
|
+
* @param fn function to call once the ratelimit is ready
|
|
254
|
+
* @param url Endpoint of the request
|
|
255
|
+
* @param method Http method used by the request
|
|
200
256
|
*/
|
|
201
|
-
|
|
257
|
+
queue<T>(fn: (bucket: Bucket) => Promise<T>, url: string, method: string): Promise<T>;
|
|
258
|
+
/**
|
|
259
|
+
* Set if this Ratelimiter is hitting a global ratelimit for `ms` duration
|
|
260
|
+
* @param ms How long in milliseconds this Ratelimiter is globally ratelimited for
|
|
261
|
+
*/
|
|
262
|
+
setGlobal(ms: number): void;
|
|
202
263
|
}
|
|
203
|
-
type RequestEventData = {
|
|
204
|
-
endpoint: string;
|
|
205
|
-
method: string;
|
|
206
|
-
dataType: "json" | "multipart";
|
|
207
|
-
data: any;
|
|
208
|
-
};
|
|
209
|
-
type HandlerEvents = {
|
|
210
|
-
request: [string, RequestEventData];
|
|
211
|
-
done: [string, Response, RequestEventData];
|
|
212
|
-
requestError: [string, Error];
|
|
213
|
-
rateLimit: [{
|
|
214
|
-
timeout: number;
|
|
215
|
-
remaining: number;
|
|
216
|
-
limit: number;
|
|
217
|
-
method: string;
|
|
218
|
-
path: string;
|
|
219
|
-
route: string;
|
|
220
|
-
}];
|
|
221
|
-
};
|
|
222
264
|
/**
|
|
223
265
|
* Request Handler class
|
|
224
266
|
* @since 0.1.0
|
|
225
267
|
*/
|
|
226
|
-
declare class RequestHandler extends EventEmitter<HandlerEvents> {
|
|
268
|
+
declare class RequestHandler extends EventEmitter$1<HandlerEvents> {
|
|
227
269
|
ratelimiter: Ratelimiter;
|
|
228
270
|
options: {
|
|
229
271
|
/** The base URL to use when making requests. Defaults to https://discord.com */
|
|
@@ -240,6 +282,7 @@ declare class RequestHandler extends EventEmitter<HandlerEvents> {
|
|
|
240
282
|
Authorization?: string;
|
|
241
283
|
"User-Agent": string;
|
|
242
284
|
};
|
|
285
|
+
fetch: typeof fetch;
|
|
243
286
|
};
|
|
244
287
|
latency: number;
|
|
245
288
|
apiURL: string;
|
|
@@ -3851,4 +3894,10 @@ declare const Endpoints: {
|
|
|
3851
3894
|
WEBHOOK_TOKEN_SLACK: (hookId: string, token: string) => `${ReturnType<typeof Endpoints.WEBHOOK_TOKEN>}/slack`;
|
|
3852
3895
|
};
|
|
3853
3896
|
|
|
3854
|
-
|
|
3897
|
+
declare function graph(stateMachine: StateMachine): string;
|
|
3898
|
+
|
|
3899
|
+
declare const graphWrapped: {
|
|
3900
|
+
graph: typeof graph;
|
|
3901
|
+
};
|
|
3902
|
+
|
|
3903
|
+
export { AssetsMethods, AuditLogMethods, AutoModerationMethods, BotMethods, Bucket, ChannelMethods, Constants, DiscordAPIError, Endpoints, EntitlementMethods as EntitlementsMethods, GuildMethods, GuildScheduledEventMethods, GuildTemplateMethods, type HTTPMethod, type HandlerEvents, InteractionMethods, InviteMethods, type RESTPostAPIAttachmentsRefreshURLsResult, type RatelimitInfo, Ratelimiter, type RequestEventData, RequestHandler, type SMHistory, type SMState, type SMTransition, SkuMethods, SnowTransfer, StageInstanceMethods, StateMachine, graphWrapped as StateMachineGraph, UserMethods, VoiceMethods, WebhookMethods, _default as tokenless };
|