forked from Crown-Studio/roblox-ts-template
28 lines
926 B
TypeScript
28 lines
926 B
TypeScript
import { Controller, OnStart } from "@flamework/core";
|
|
import Log from "@rbxts/log";
|
|
import { TextChatService } from "@rbxts/services";
|
|
import { WELCOME_CHAT, WELCOME_CHAT_MESSAGE } from "shared/welcome-chat";
|
|
|
|
@Controller()
|
|
export class WelcomeChatController implements OnStart {
|
|
public onStart(): void {
|
|
task.delay(WELCOME_CHAT.delaySeconds, () => this.displayWelcome());
|
|
}
|
|
|
|
private displayWelcome(): void {
|
|
const deadline = os.clock() + WELCOME_CHAT.channelTimeoutSeconds;
|
|
const channels = TextChatService.WaitForChild(
|
|
"TextChannels",
|
|
WELCOME_CHAT.channelTimeoutSeconds,
|
|
);
|
|
const channel = channels?.WaitForChild("RBXGeneral", math.max(deadline - os.clock(), 0));
|
|
|
|
if (!channel?.IsA("TextChannel")) {
|
|
Log.Warn("Welcome chat unavailable: RBXGeneral did not become ready before the timeout");
|
|
return;
|
|
}
|
|
|
|
channel.DisplaySystemMessage(WELCOME_CHAT_MESSAGE);
|
|
}
|
|
}
|