Advertisement
osmarks

Chatbox Command Spy

Jan 27th, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.79 KB | None | 0 0
  1. local function fwrite(n, c)
  2.     local f = fs.open(n, "w")
  3.     f.write(c)
  4.     f.close()
  5. end
  6.  
  7. local function fread(n)
  8.     local f = fs.open(n, "r")
  9.     local out = f.readAll()
  10.     f.close()
  11.     return out
  12. end
  13.  
  14. local file = "gccs"
  15. local optins = textutils.unserialise(fread(file))
  16.  
  17. local function save()
  18.     fwrite(file, textutils.serialise(optins))
  19. end
  20.  
  21. local chatbox = peripheral.find "chat_box"
  22.  
  23. while true do
  24.     local _, sender, type, arguments = os.pullEvent "command"
  25.     if type == "gccs-optin" then
  26.         optins[sender] = true
  27.         save()
  28.     elseif type == "gccs-optout" then
  29.         optins[sender] = nil
  30.         save()
  31.     end
  32.     local text = sender .. ": \\" .. type .. " " .. table.concat(arguments, " ")
  33.    
  34.     for user in pairs(optins) do
  35.         chatbox.tell(user, text, "\167bG\167aCCS\1677", "\1678")
  36.     end
  37. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement