Skip to content

Commit

Permalink
Fix moderation taking ages to load
Browse files Browse the repository at this point in the history
  • Loading branch information
AL1L committed Jul 30, 2023
1 parent 7e814e0 commit 5a1a470
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
2 changes: 1 addition & 1 deletion default.project.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"Version": {
"$className": "StringValue",
"$properties": {
"Value": "v1.122.4"
"Value": "v1.122.5"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bloxadmin-sdk",
"version": "1.122.4",
"version": "1.122.5",
"description": "",
"main": "src/lib.ts",
"scripts": {
Expand Down
30 changes: 26 additions & 4 deletions src/BloxAdmin.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
const startedAt = os.clock();
const importTims: Record<string, number> = {};
let importStart = os.clock();
function importTime(name: string) {
const took = os.clock() - importStart;
importTims[name] = took;
importStart = os.clock();
return took;
}
import EventEmitter from "EventEmitter";
importTime("EventEmitter");
import Logger from "Logger";
importTime("Logger");
import { Module } from "Module";
importTime("Module");
import RemoteMessaging from "RemoteMessaging";
importTime("RemoteMessaging");
import { DEFAULT_CONFIG } from "consts";
importTime("consts");
import Actions from "modules/Actions";
importTime("Actions");
import Analytics from "modules/Analytics";
importTime("Analytics");
import DebugUI from "modules/DebugUI";
importTime("DebugUI");
import Metrics from "modules/Metrics";
importTime("Metrics");
import Moderation from "modules/Moderation";
importTime("Moderation");
import RemoteConfig from "modules/RemoteConfig";
importTime("RemoteConfig");
import Shutdown from "modules/Shutdown";
importTime("Shutdown");
import { Config, EventType, InitConfig } from "types";
importTime("types");
const importsTook = os.clock() - startedAt;

export type InitBloxAdmin = (apiKey?: string, config?: InitConfig) => BloxAdmin;

Expand Down Expand Up @@ -299,21 +321,21 @@ export default function init(apiKey?: string, config: InitConfig = {}) {

if (g.bloxadmin) {
ba = g.bloxadmin;
ba.logger.debug(`Updating config`);
ba.updateConfig(config);
} else {
const started = os.clock();
ba = new BloxAdmin(config);
g.bloxadmin = ba;

ba.logger.debug(`Initialized in ${os.clock() - started}s`);
ba.logger.debug(`Imports in ${importsTook}s`);
print(importTims)
ba.logger.debug(`Loaded in ${os.clock() - startedAt}s`);
}

if (apiKey) {
const start = coroutine.create(() => {
ba.start(apiKey);
});
coroutine.resume(start);
ba.start(apiKey);
}

return ba;
Expand Down
27 changes: 22 additions & 5 deletions src/modules/Moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ import { Module } from "Module";
import { ChatChannel, ChatService, EventType } from "types";

const Players = game.GetService("Players");
const ChatServiceModule = game
.GetService("ServerScriptService")
?.WaitForChild("ChatServiceRunner", 10)
?.WaitForChild("ChatService", 10) as ModuleScript | undefined;
const ChatService = ChatServiceModule ? require(ChatServiceModule) as ChatService : undefined;
const TextChatService = game.GetService("TextChatService");

export enum ModerationType {
Expand Down Expand Up @@ -84,6 +79,7 @@ export default class Moderation extends Module<{
private playersMutedUntil: Record<number, number> = {};
private lastNotifiedMuted: Record<number, number> = {};
private systemMessageEvent: RemoteEvent<(data: string) => void>;
private ChatService: ChatService | undefined;

// private autoModEnabled = false;
// private autoModTime = 0;
Expand Down Expand Up @@ -170,12 +166,32 @@ export default class Moderation extends Module<{
})
}

chatService() {
if (this.ChatService) return this.ChatService;

const ChatServiceModule = game
.GetService("ServerScriptService")
?.WaitForChild("ChatServiceRunner", 10)
?.WaitForChild("ChatService", 10) as ModuleScript | undefined;
const ChatService = ChatServiceModule ? require(ChatServiceModule) as ChatService : undefined;

if (!ChatService) {
this.logger.warn("ChatService not found");
return undefined;
}

this.ChatService = ChatService;

return ChatService;
}

kick(player: Player, reason?: string) {
this.logger.info(`Kicking ${player.Name} for ${reason}`);
player.Kick(reason);
}

private muteLegacy(player: Player, seconds?: number, reason?: string) {
const ChatService = this.chatService()
if (!ChatService) return;

const speaker = ChatService.GetSpeaker(player.Name);
Expand Down Expand Up @@ -256,6 +272,7 @@ export default class Moderation extends Module<{
}

private unmuteLegacy(player: Player, reason?: string) {
const ChatService = this.chatService()
if (!ChatService) return;

const speaker = ChatService.GetSpeaker(player.Name);
Expand Down

0 comments on commit 5a1a470

Please sign in to comment.