feat: base plugin lib idea (#2308)

* feat: base plugin lib idea

* fix: stuff

* fmt

* fix: imports and exports

* fix: errors & tests

* fix: remove logs
This commit is contained in:
Skillz4Killz
2022-06-18 18:46:37 -04:00
committed by GitHub
parent 181f39bc2b
commit ffe7cdbc6f
345 changed files with 809 additions and 739 deletions
+7
View File
@@ -0,0 +1,7 @@
import { GatewayManager } from "./manager/gatewayManager.ts";
export function calculateShardId(gateway: GatewayManager, guildId: bigint) {
if (gateway.manager.totalShards === 1) return 0;
return Number((guildId >> 22n) % BigInt(gateway.manager.totalShards - 1));
}
+4 -6
View File
@@ -1,8 +1,6 @@
import { GetGatewayBot } from "../../transformers/gatewayBot.ts";
import { DiscordGatewayPayload } from "../../types/discord.ts";
import { GatewayIntents, MakeRequired, OmitFirstFnArg, PickPartial } from "../../types/shared.ts";
import { GatewayBot, PickPartial } from "../../types/shared.ts";
import { LeakyBucket } from "../../util/bucket.ts";
import { Collection } from "../../util/collection.ts";
import { CreateShard, createShard } from "../shard/createShard.ts";
import { Shard, ShardGatewayConfig } from "../shard/types.ts";
import { calculateTotalShards } from "./calculateTotalShards.ts";
@@ -48,7 +46,7 @@ export function createGatewayManager(
/** The max concurrency buckets.
* Those will be created when the `spawnShards` (which calls `prepareBuckets` under the hood) function gets called.
*/
buckets: new Collection<
buckets: new Map<
number,
{
workers: { id: number; queue: number[] }[];
@@ -222,7 +220,7 @@ export interface CreateGatewayManager {
lastShardId: number;
/** Important data which is used by the manager to connect shards to the gateway. */
gatewayBot: GetGatewayBot;
gatewayBot: GatewayBot;
gatewayConfig: PickPartial<ShardGatewayConfig, "token">;
@@ -230,7 +228,7 @@ export interface CreateGatewayManager {
createShardOptions?: Omit<CreateShard, "id" | "totalShards" | "requestIdentify" | "gatewayConfig">;
/** Stored as bucketId: { workers: [workerId, [ShardIds]], createNextShard: boolean } */
buckets: Collection<
buckets: Map<
number,
{
workers: { id: number; queue: number[] }[];
+1 -1
View File
@@ -1,4 +1,4 @@
import { delay } from "../../util/utils.ts";
import { delay } from "../../util/delay.ts";
import { GatewayManager } from "./gatewayManager.ts";
export async function stop(gateway: GatewayManager, code: number, reason: string) {
+2 -3
View File
@@ -12,7 +12,6 @@ import {
ShardSocketRequest,
ShardState,
} from "./types.ts";
import { StatusUpdate } from "../../helpers/misc/editShardStatus.ts";
import { startHeartbeating } from "./startHeartbeating.ts";
import { stopHeartbeating } from "./stopHeartbeating.ts";
import { resume } from "./resume.ts";
@@ -24,7 +23,7 @@ import { connect } from "./connect.ts";
import { close } from "./close.ts";
import { shutdown } from "./shutdown.ts";
import { isOpen } from "./isOpen.ts";
import { DiscordGatewayPayload } from "../../types/discord.ts";
import { DiscordGatewayPayload, DiscordStatusUpdate } from "../../types/discord.ts";
import { GatewayIntents, PickPartial } from "../../types/shared.ts";
import { API_VERSION } from "../../util/constants.ts";
@@ -275,7 +274,7 @@ export interface CreateShard {
isOpen?: typeof isOpen;
/** Function which can be overwritten in order to get the shards presence. */
makePresence?(shardId: number): Promise<StatusUpdate> | StatusUpdate;
makePresence?(shardId: number): Promise<DiscordStatusUpdate> | DiscordStatusUpdate;
/** The maximum of requests which can be send to discord per rate limit tick.
* Typically this value should not be changed.
+1 -1
View File
@@ -1,7 +1,7 @@
import { DiscordGatewayPayload, DiscordHello, DiscordReady } from "../../types/discord.ts";
import { GatewayOpcodes } from "../../types/shared.ts";
import { createLeakyBucket } from "../../util/bucket.ts";
import { delay } from "../../util/utils.ts";
import { delay } from "../../util/delay.ts";
import { decompressWith } from "./deps.ts";
import { GATEWAY_RATE_LIMIT_RESET_INTERVAL, Shard, ShardState } from "./types.ts";
-2
View File
@@ -1,7 +1,5 @@
import { StatusUpdate } from "../../helpers/misc/editShardStatus.ts";
import { DiscordGatewayPayload } from "../../types/discord.ts";
import { GatewayOpcodes } from "../../types/shared.ts";
import { LeakyBucket } from "../../util/bucket.ts";
import { createShard } from "./createShard.ts";
// TODO: think whether we also need an identifiedShard function