Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Автор: qwertyMAN
- -- Версия: 0.1
- -- Специально для computercraft.ru
- local event = require("event")
- local term = require("term")
- local com = require("component")
- local gpu = com.gpu
- local chat = com.chatbox
- local old_Foreg = gpu.getForeground()
- local old_Back = gpu.getBackground()
- local exit = true
- local white_list = {}
- local color = {
- Foreg = 0xffffff
- }
- local command = {
- ["clear"] = term.clear,
- ["add"] = function(msg)
- gpu.setForeground(0xffff00)
- for i=2, #msg do
- print("User " .. msg[i] .. " added")
- white_list[#white_list+1] = msg[i]
- end
- gpu.setForeground(color.Foreg)
- end,
- ["del"] = function(msg)
- gpu.setForeground(0xff0000)
- if msg[2] == "all" then
- for i=#white_list, 1, -1 do
- print("User " .. white_list[i] .. " removed")
- table.remove(white_list,i)
- end
- gpu.setForeground(0xffff00)
- print("White list clear")
- else
- for i=2, #msg do
- for j=1, #white_list do
- if msg[i]==white_list[j] then
- print("User " .. msg[i] .. " removed")
- table.remove(white_list,j)
- break
- end
- end
- end
- end
- gpu.setForeground(color.Foreg)
- end,
- ["list"] = function(msg)
- gpu.setForeground(0x00ff00)
- print("White list:")
- if #white_list==0 then
- gpu.setForeground(0xffff00)
- print("none")
- else
- for i=1, #white_list do
- print(white_list[i])
- end
- end
- gpu.setForeground(color.Foreg)
- end,
- ["exit"] = function(msg)
- gpu.setForeground(old_Foreg)
- gpu.setBackground(old_Back)
- term.clear()
- print("Good buy!")
- os.sleep(1)
- term.clear()
- exit = false
- end
- }
- local function args_word(words)
- local tb = {}
- for word in string.gmatch(words, "%a+") do
- tb[#tb+1] = word
- end
- return tb
- end
- local function cmd(_,_,name,msg)
- msg = args_word(msg)
- if command[msg[1]] then
- command[msg[1]](msg)
- end
- end
- local function msg(_,_,name,msg)
- if #white_list == 0 then
- print(name .. " : " .. msg)
- else
- for i=1, #white_list do
- if name == white_list[i] then
- print(name .. " : " .. msg)
- end
- end
- end
- end
- function start()
- term.clear()
- event.listen("chat_command",cmd)
- event.listen("chat_message",msg)
- while exit do
- os.sleep(3)
- end
- event.ignore("chat_command",cmd)
- event.ignore("chat_message",msg)
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement