Fix: typing (#2589)

* deno fmt

* import SortOrderTypes

* add bigString to reverse snowflake
This commit is contained in:
Jonathan Ho
2022-11-14 15:49:25 -06:00
committed by GitHub
parent e59ec94f55
commit 5a1887462d
9 changed files with 13 additions and 9 deletions
+1 -1
View File
@@ -421,7 +421,7 @@ export interface Transformers {
user: (bot: Bot, payload: User) => DiscordUser;
team: (bot: Bot, payload: Team) => DiscordTeam;
application: (bot: Bot, payload: Application) => DiscordApplication;
snowflake: (snowflake: bigint) => string;
snowflake: (snowflake: BigString) => string;
createApplicationCommand: (bot: Bot, payload: CreateApplicationCommand) => DiscordCreateApplicationCommand;
applicationCommand: (bot: Bot, payload: ApplicationCommand) => DiscordApplicationCommand;
applicationCommandOption: (bot: Bot, payload: ApplicationCommandOption) => DiscordApplicationCommandOption;
+3 -1
View File
@@ -18,7 +18,9 @@ export function calculateBasePermissions(
memberOrId: bigint | Member,
) {
const guild = typeof guildOrId === "bigint" ? bot.guilds.get(guildOrId) : guildOrId;
const member = typeof memberOrId === "bigint" ? bot.members.get(bot.transformers.snowflake(`${memberOrId}${guild?.id}`)) : memberOrId;
const member = typeof memberOrId === "bigint"
? bot.members.get(bot.transformers.snowflake(`${memberOrId}${guild?.id}`))
: memberOrId;
if (!guild || !member) return 8n;
+1 -1
View File
@@ -30,6 +30,6 @@ export function isQueueClearable(queue: QueueBucket) {
if (!queue.interval) return false;
if (queue.processing) return false;
if (queue.processingPending) return false;
return true;
}
+1 -1
View File
@@ -72,7 +72,7 @@ export function createInvalidRequestBucket(options: InvalidRequestBucketOptions)
if (!bucket.errorStatuses.includes(code)) return;
// Shared scope is not considered invalid
if (code === 429 && sharedScope) return;
// INVALID REQUEST WAS MADE
// If it was not frozen before, mark it frozen
-2
View File
@@ -70,9 +70,7 @@ export function createQueueBucket(rest: RestManager, options: QueueBucketOptions
bucket.processingPending = true;
while (bucket.pending.length) {
if (bucket.firstRequest || bucket.isRequestAllowed()) {
const [queuedRequest] = bucket.pending;
if (queuedRequest) {
const basicURL = rest.simplifyUrl(queuedRequest.request.url, queuedRequest.request.method);
+1 -1
View File
@@ -1,4 +1,4 @@
import { RestRequest,RestPayload } from "./rest.ts";
import { RestPayload, RestRequest } from "./rest.ts";
import { RestManager } from "./restManager.ts";
export async function processGlobalQueue(rest: RestManager, request: {
+4 -1
View File
@@ -97,7 +97,10 @@ export async function sendRequest<T>(rest: RestManager, options: RestSendRequest
return;
} // RATE LIMITED, ADD BACK TO QUEUE
else {
rest.invalidBucket.handleCompletedRequest(response.status, response.headers.get('X-RateLimit-Scope') === 'shared');
rest.invalidBucket.handleCompletedRequest(
response.status,
response.headers.get("X-RateLimit-Scope") === "shared",
);
await delay(json.retry_after * 1000);
return options.retryRequest?.();
}
+1
View File
@@ -30,6 +30,7 @@ import {
ScheduledEventEntityType,
ScheduledEventPrivacyLevel,
ScheduledEventStatus,
SortOrderTypes,
StickerFormatTypes,
StickerTypes,
SystemChannelFlags,
+1 -1
View File
@@ -4,6 +4,6 @@ export function snowflakeToBigint(snowflake: BigString) {
return BigInt(snowflake) | 0n;
}
export function bigintToSnowflake(snowflake: bigint) {
export function bigintToSnowflake(snowflake: BigString) {
return snowflake === 0n ? "" : snowflake.toString();
}