Skip to content

Commit

Permalink
Support new TextChatService for chat binds (#322)
Browse files Browse the repository at this point in the history
Add support for both legacy Chat service and new TextChatService for player-targeted binds
  • Loading branch information
Krcnos authored Mar 7, 2024
1 parent 2f3c1e1 commit 232064c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Cmdr/BuiltInCommands/Utility/bind.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local UserInputService = game:GetService("UserInputService")
local TextChatService = game:GetService("TextChatService")

return {
Name = "bind",
Expand Down Expand Up @@ -52,7 +53,7 @@ return {
elseif bindType == "bindableResource" then
return "Unimplemented..."
elseif bindType == "player" then
binds[bind] = bind.Chatted:Connect(function(message)
local function RunCommand(message)
local args = { message }
local chatCommand = context.Cmdr.Util.RunEmbeddedCommands(
context.Dispatcher,
Expand All @@ -62,7 +63,15 @@ return {
("%s $ %s : %s"):format(bind.Name, chatCommand, context.Dispatcher:EvaluateAndRun(chatCommand)),
Color3.fromRGB(244, 92, 66)
)
end)
end

if TextChatService.ChatVersion == Enum.ChatVersion.LegacyChatService then
binds[bind] = bind.Chatted:Connect(RunCommand)
else
binds[bind] = TextChatService.SendingMessage:Connect(function(message)
RunCommand(message.Text)
end)
end
end

return "Bound command to input."
Expand Down

0 comments on commit 232064c

Please sign in to comment.