Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local chatBox = peripheral.find("chatbox_admin") or peripheral.find("chatbox")
- function chatBoxSay(message)
- if not message then return false end
- message = string.gsub(message,"&s","\194\167")
- chatBox.say(message)
- return true
- end
- function chatBoxTell(user,message)
- if not message or user then return false end
- message = string.gsub(message,"&s","\194\167")
- chatBox.tell(user,message)
- return true
- end
- function chatBoxSeeLabel()
- return chatBox.getLabel()
- end
- function chatBoxSetLabel(label)
- if not label then return false end
- chatBox.setLabel(label)
- return true
- end
- function log(file,text)
- if not logHandle then logHandle = fs.open("chatLog","a") end
- logHandle.writeLine(text)
- logHandle.flush()
- end
- function getArgs()
- if #cmdArgs == 0 then return {} end
- local arguments = {}
- for i=2,#cmdArgs,1 do
- table.insert(arguments,cmdArgs[i])
- end
- return arguments
- end
- function addHelp(command,description)
- if not description then discription = nil end
- if not command then return end
- helpList[command] = description
- return true
- end
- function removeHelp(command)
- if not helpList[command] then return false end
- table.remove(helpList,command)
- return true
- end
- config = {}
- config.label = "Rocky"
- config.scriptRoot = "/cbscripts/"
- config.useGlobal = true
- config.logFile = "chat.log"
- config.logChat = false
- helpList = {}
- chatBoxSetLabel(config.label)
- addHelp("help","Shows what other scripts have added to help you")
- addHelp("scripts","Shows all avaliable scripts")
- chatBoxSay("Im ready :D")
- while true do
- local _,_,username,message = os.pullEvent("chat_message")
- cmdArgs = {}
- for arg in message:gmatch("%w+") do table.insert(cmdArgs,arg) end
- cmdTxt = {}
- for i=1,#message,1 do table.insert(cmdTxt,string.sub(message,i,i)) end
- print(username .. ": " .. table.concat(cmdArgs,","))
- if config.logChat then
- log(config.logFile,"[" .. username .. "] " .. message)
- end
- if not config.useGlobal then
- local say = chatBoxSay
- function chatBoxSay(message)
- return chatBoxTell(username,message)
- end
- end
- if cmdTxt[1] == "!" then
- log(config.logFile,"[Execute] " .. username .. ": " .. table.concat(cmdArgs,","))
- if cmdArgs[1] == "scripts" then
- chatBoxSay("Scripts (" .. #fs.list(config.scriptRoot) .."): " ..table.concat(fs.list(config.scriptRoot),","))
- elseif cmdArgs[1] == "help" then
- chatBoxSay("Help:")
- for i,k in pairs(helpList) do
- chatBoxSay("!" .. i .. ": " .. k)
- end
- elseif fs.exists(fs.combine(config.scriptRoot,cmdArgs[1])) then
- shell.run(fs.combine(config.scriptRoot,cmdArgs[1]))
- else
- chatBoxSay("Unknown command. Type \"!help\" for help.")
- end
- end
- if not config.useGlobal then
- chatBoxSay = say
- end
- sleep(0)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement