perf: tune selfbot runtime defaults
Apply low-memory client options and point the workspace vendor package at the optimized selfbot internals for more stable long-running moderation capture. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
21
src/discordClientOptions.ts
Normal file
21
src/discordClientOptions.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { type ClientOptions, Options } from "discord.js-selfbot-v13";
|
||||||
|
|
||||||
|
export function createDiscordClientOptions(): ClientOptions {
|
||||||
|
return {
|
||||||
|
makeCache: Options.cacheWithLimits({
|
||||||
|
...Options.defaultMakeCacheSettings,
|
||||||
|
MessageManager: 25,
|
||||||
|
ReactionManager: 0,
|
||||||
|
ReactionUserManager: 0,
|
||||||
|
PresenceManager: 0,
|
||||||
|
}),
|
||||||
|
partials: ["USER", "CHANNEL", "GUILD_MEMBER", "MESSAGE"],
|
||||||
|
sweepers: {
|
||||||
|
messages: { interval: 300, lifetime: 600 },
|
||||||
|
threads: { interval: 3600, lifetime: 14400 },
|
||||||
|
},
|
||||||
|
restRequestTimeout: 15_000,
|
||||||
|
retryLimit: 2,
|
||||||
|
restGlobalRateLimit: 45,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import "dotenv/config";
|
|||||||
import { Client } from "discord.js-selfbot-v13";
|
import { Client } from "discord.js-selfbot-v13";
|
||||||
import { config } from "./config";
|
import { config } from "./config";
|
||||||
import { closeDatabase, initializeDatabase } from "./database/drizzle";
|
import { closeDatabase, initializeDatabase } from "./database/drizzle";
|
||||||
|
import { createDiscordClientOptions } from "./discordClientOptions";
|
||||||
import { createChildLogger } from "./logger";
|
import { createChildLogger } from "./logger";
|
||||||
import { startPendingAIAnalysisWorker } from "./moderation/aiAnalyzer";
|
import { startPendingAIAnalysisWorker } from "./moderation/aiAnalyzer";
|
||||||
import { syncBacklogMessages } from "./moderation/backlogSync";
|
import { syncBacklogMessages } from "./moderation/backlogSync";
|
||||||
@@ -22,7 +23,7 @@ logger.info(
|
|||||||
);
|
);
|
||||||
|
|
||||||
logger.info("Creating Discord client");
|
logger.info("Creating Discord client");
|
||||||
const client = new Client();
|
const client = new Client(createDiscordClientOptions());
|
||||||
const voiceController = new VoiceController(client);
|
const voiceController = new VoiceController(client);
|
||||||
|
|
||||||
let isShuttingDown = false;
|
let isShuttingDown = false;
|
||||||
|
|||||||
15
tests/vendor/requestHandlerBackoff.test.ts
vendored
Normal file
15
tests/vendor/requestHandlerBackoff.test.ts
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
const { calculateRetryDelay } = await import(
|
||||||
|
"../../vendor/discord.js-selfbot-v13/src/rest/RequestHandler.js"
|
||||||
|
);
|
||||||
|
|
||||||
|
describe("calculateRetryDelay", () => {
|
||||||
|
it("increases exponentially and applies bounded jitter", () => {
|
||||||
|
expect(calculateRetryDelay(1, () => 0)).toBe(250);
|
||||||
|
expect(calculateRetryDelay(2, () => 0)).toBe(500);
|
||||||
|
expect(calculateRetryDelay(3, () => 0)).toBe(1000);
|
||||||
|
expect(calculateRetryDelay(10, () => 0)).toBe(5000);
|
||||||
|
expect(calculateRetryDelay(1, () => 0.999)).toBe(499);
|
||||||
|
});
|
||||||
|
});
|
||||||
22
tests/vendor/selfbotClientOptions.test.ts
vendored
Normal file
22
tests/vendor/selfbotClientOptions.test.ts
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { createDiscordClientOptions } from "../../src/discordClientOptions";
|
||||||
|
|
||||||
|
describe("createDiscordClientOptions", () => {
|
||||||
|
it("uses low-memory message cache and active sweepers", () => {
|
||||||
|
const options = createDiscordClientOptions();
|
||||||
|
|
||||||
|
expect(options.restRequestTimeout).toBe(15_000);
|
||||||
|
expect(options.retryLimit).toBe(2);
|
||||||
|
expect(options.restGlobalRateLimit).toBe(45);
|
||||||
|
expect(options.sweepers).toEqual({
|
||||||
|
messages: { interval: 300, lifetime: 600 },
|
||||||
|
threads: { interval: 3600, lifetime: 14400 },
|
||||||
|
});
|
||||||
|
expect(options.partials).toEqual([
|
||||||
|
"USER",
|
||||||
|
"CHANNEL",
|
||||||
|
"GUILD_MEMBER",
|
||||||
|
"MESSAGE",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
2
vendor/discord.js-selfbot-v13
vendored
2
vendor/discord.js-selfbot-v13
vendored
Submodule vendor/discord.js-selfbot-v13 updated: 66e212677c...d011eed711
Reference in New Issue
Block a user