Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add way to send system messages to ChatProviderService #520

Merged
merged 6 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/chatproviderservice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@quenty/playerutils": "file:../playerutils",
"@quenty/preferredparentutils": "file:../preferredparentutils",
"@quenty/promise": "file:../promise",
"@quenty/remoting": "file:../remoting",
"@quenty/richtext": "file:../richtext",
"@quenty/rx": "file:../rx",
"@quenty/rxbinderutils": "file:../rxbinderutils",
Expand Down
52 changes: 51 additions & 1 deletion src/chatproviderservice/src/Client/ChatProviderServiceClient.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

local require = require(script.Parent.loader).load(script)

local TextChatService = game:GetService("TextChatService")
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")

local Maid = require("Maid")
local Signal = require("Signal")
Expand Down Expand Up @@ -36,6 +37,27 @@ function ChatProviderServiceClient:Start()
TextChatService.OnIncomingMessage = function(textChatMessage)
self.MessageIncoming:Fire(textChatMessage)

local metadata = textChatMessage.Metadata
if metadata then
local success, decodedMessageData = pcall(function()
return HttpService:JSONDecode(metadata)
end)

if success and decodedMessageData then
local color = decodedMessageData.Color or "#ffffff"
local isValidHex = pcall(function()
return Color3.fromHex(color)
end)

if isValidHex then
local overrideProperties = Instance.new("TextChatMessageProperties")
overrideProperties.Text = `<font color="#{color}">{textChatMessage.Text}</font>`

return overrideProperties
end
end
end

local textSource = textChatMessage.TextSource
if not textSource then
return
Expand All @@ -53,6 +75,34 @@ function ChatProviderServiceClient:Start()
end
end

--[=[
Sends a system message to the provided TextChannel.
@param encodedMessageData string
@param channel TextChannel?
]=]
function ChatProviderServiceClient:SendSystemMessage(message: string, encodedMessageData: string?, channel: TextChannel?)
assert(typeof(message) == "string", "[ChatProviderServiceClient.SendSystemMessage] - Bad message")

if not channel then
local channels = TextChatService:FindFirstChild("TextChannels")
unrooot marked this conversation as resolved.
Show resolved Hide resolved
if not channels then
return
end

local general = channels:FindFirstChild("RBXGeneral")
if general then
channel = general
end
end

if not channel then
warn("[ChatProviderServiceClient.SendSystemMessage] - Failed to get default channel")
return
end

channel:DisplaySystemMessage(message, encodedMessageData)
end

function ChatProviderServiceClient:_renderTags(textSource)
local player = Players:GetPlayerByUserId(textSource.UserId)
if not player then
Expand Down
Loading