local z=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local s=game:GetService("\084\101\120\116\067\104\097\116\083\101\114\118\105\099\101")return{Name="\098\105\110\100",Aliases={},Description="\066\105\110\100\115 \097 \099\111\109\109\097\110\100 \115\116\114\105\110\103 \116\111 \097 \107\101\121 \111\114 \109\111\117\115\101 \105\110\112\117\116\046",Group="\068\101\102\097\117\108\116\085\116\105\108",Args={{Type="\117\115\101\114\073\110\112\117\116 \033 \098\105\110\100\097\098\108\101\082\101\115\111\117\114\099\101 \064 \112\108\097\121\101\114",Name="\073\110\112\117\116",Description="\084\104\101 \107\101\121 \111\114 \105\110\112\117\116 \116\121\112\101 \121\111\117\'\100 \108\105\107\101 \116\111 \098\105\110\100 \116\104\101 \099\111\109\109\097\110\100 \116\111\046"};{Type="\099\111\109\109\097\110\100",Name="\067\111\109\109\097\110\100",Description="\084\104\101 \099\111\109\109\097\110\100 \121\111\117 \119\097\110\116 \116\111 \114\117\110 \111\110 \116\104\105\115 \105\110\112\117\116"},{Type="\115\116\114\105\110\103";Name="\065\114\103\117\109\101\110\116\115",Description="\084\104\101 \097\114\103\117\109\101\110\116\115 \102\111\114 \116\104\101 \099\111\109\109\097\110\100",Default=""}},ClientRun=function(B,o,X,G)local Y=B:GetStore("\067\077\068\082\095\066\105\110\100\115")X=X..(" "..G)if Y[o]then Y[o]:Disconnect()end local r=(B:GetArgument(1)).Type.Name if r=="\117\115\101\114\073\110\112\117\116"then Y[o]=z.InputBegan:Connect(function(z,s)if s then return end if z.UserInputType==o or z.KeyCode==o then B:Reply(B.Dispatcher:EvaluateAndRun(B.Cmdr.Util.RunEmbeddedCommands(B.Dispatcher,X)))end end)elseif r=="\098\105\110\100\097\098\108\101\082\101\115\111\117\114\099\101"then return"\085\110\105\109\112\108\101\109\101\110\116\101\100\046\046\046"elseif r=="\112\108\097\121\101\114"then local function z(z)local s={z}local G=B.Cmdr.Util.RunEmbeddedCommands(B.Dispatcher,B.Cmdr.Util.SubstituteArgs(X,s))B:Reply(("\037\115 \036 \037\115 \058 \037\115"):format(o.Name,G,B.Dispatcher:EvaluateAndRun(G)),Color3.fromRGB(244,92,66))end if s.ChatVersion==Enum.ChatVersion.LegacyChatService then Y[o]=o.Chatted:Connect(z)else Y[o]=s.SendingMessage:Connect(function(s)z(s.Text)end)end end return"\066\111\117\110\100 \099\111\109\109\097\110\100 \116\111 \105\110\112\117\116\046"end}
local UserInputService = game:GetService("UserInputService")
local TextChatService = game:GetService("TextChatService")

return {
	Name = "bind",
	Aliases = {},
	Description = "Binds a command string to a key or mouse input.",
	Group = "DefaultUtil",
	Args = {
		{
			Type = "userInput ! bindableResource @ player",
			Name = "Input",
			Description = "The key or input type you'd like to bind the command to.",
		},
		{
			Type = "command",
			Name = "Command",
			Description = "The command you want to run on this input",
		},
		{
			Type = "string",
			Name = "Arguments",
			Description = "The arguments for the command",
			Default = "",
		},
	},

	ClientRun = function(context, bind, command, arguments)
		local binds = context:GetStore("CMDR_Binds")

		command = command .. " " .. arguments

		if binds[bind] then
			binds[bind]:Disconnect()
		end

		local bindType = context:GetArgument(1).Type.Name

		if bindType == "userInput" then
			binds[bind] = UserInputService.InputBegan:Connect(function(input, gameProcessed)
				if gameProcessed then
					return
				end

				if input.UserInputType == bind or input.KeyCode == bind then
					context:Reply(
						context.Dispatcher:EvaluateAndRun(
							context.Cmdr.Util.RunEmbeddedCommands(context.Dispatcher, command)
						)
					)
				end
			end)
		elseif bindType == "bindableResource" then
			return "Unimplemented..."
		elseif bindType == "player" then
			local function RunCommand(message)
				local args = { message }
				local chatCommand = context.Cmdr.Util.RunEmbeddedCommands(
					context.Dispatcher,
					context.Cmdr.Util.SubstituteArgs(command, args)
				)
				context:Reply(
					("%s $ %s : %s"):format(bind.Name, chatCommand, context.Dispatcher:EvaluateAndRun(chatCommand)),
					Color3.fromRGB(244, 92, 66)
				)
			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."
	end,
}
