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
Changes from 1 commit
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
50 changes: 36 additions & 14 deletions 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 @@ -38,15 +39,22 @@ function ChatProviderServiceClient:Start()

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

if isValidColor then
local overrideProperties = Instance.new("TextChatMessageProperties")
overrideProperties.Text = `<font color="#{metadata}">{textChatMessage.Text}</font>`
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
return overrideProperties
end
end
end

Expand All @@ -69,16 +77,30 @@ end

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

channel:DisplaySystemMessage(message, color and color:ToHex())
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)
Expand Down
Loading