Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function string.starts(String, Start)
- return string.sub(String, 1, string.len(Start)) == Start
- end
- function string.split(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t = {}
- for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
- table.insert(t, str)
- end
- return t
- end
- local chat = peripheral.wrap("left")
- local player = peripheral.wrap("right")
- rednet.open("back")
- local whitelist = {
- ["User9684"] = true
- }
- local whitelistedSenderIds = {
- [2] = true
- }
- local prefix = "%"
- local name = "robot"
- local commands = {}
- function commands.say(caller, args)
- local includeName = (args[1] == "1")
- table.remove(args, 1)
- local text = table.concat(args, " ")
- if includeName then
- text = caller .. ": " .. text
- end
- print(caller .. ": " .. table.concat(args, " "))
- chat.sendMessage(text, name)
- end
- function commands.rename(caller, args)
- name = table.concat(args, " ")
- end
- local function execCommand(caller, text, isRemote)
- if whitelist[caller] or (isRemote and whitelistedSenderIds[caller]) then
- for commandName, commandFunc in next, commands do
- if string.starts(string.lower(text), prefix .. commandName) then
- local args = string.split(text, " ")
- table.remove(args, 1)
- commandFunc(caller, args)
- end
- end
- end
- end
- while true do
- local event, m, n, t = os.pullEvent()
- local validEvent1 = (event == "rednet_message" and t == "computercmd")
- local validEvent2 = (event == "chat")
- if validEvent1 or validEvent2 then
- print(event, m, n, t)
- execCommand(m, n, (event == 'rednet_message'))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement