Advertisement
ohmaga

SRH

Aug 1st, 2014
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.77 KB | None | 0 0
  1. -- BEGIN
  2. -- DEFINE 'SRH'
  3. -- BOOT SEQUENCE
  4. local whitelist = {
  5.     justync7 = true,
  6.     whateveryournameis = true,
  7.     lurquhar1221 = true
  8. }
  9.  
  10. local prefix = "$$^"
  11. local chatbox = peripheral.find("chatbox")
  12.  
  13. function split(pString, pPattern)
  14.    local Table = {}  -- NOTE: use {n = 0} in Lua-5.0
  15.    local fpat = "(.-)" .. pPattern
  16.    local last_end = 1
  17.    local s, e, cap = pString:find(fpat, 1)
  18.    while s do
  19.       if s ~= 1 or cap ~= "" then
  20.      table.insert(Table,cap)
  21.       end
  22.       last_end = e+1
  23.       s, e, cap = pString:find(fpat, last_end)
  24.    end
  25.    if last_end <= #pString then
  26.       cap = pString:sub(last_end)
  27.       table.insert(Table, cap)
  28.    end
  29.    return Table
  30. end
  31.  
  32. function RunCommand(msg, player)
  33.     print(user..":"..msg)
  34.     args = split(msg, " ")
  35.     if args[1] == "fuck" and args[2] == "you" then
  36.         chatbox.tell(player, "Fuck you too!")
  37.     elseif msg:sub(1,3) == "run" then
  38.         local func, err = loadstring(msg:sub(5))
  39.         if func then
  40.             local ok, err = pcall(func)
  41.             if not ok then
  42.                 chatbox.tell(player, "Error: "..tostring(err))
  43.             else
  44.                 chatbox.tell(player, "Result: "..tostring(err))
  45.             end
  46.         else
  47.             chatbox.tell(player, "Error loading function: "..tostring(err))
  48.         end
  49.     elseif msg:sub(1,4) == "calc" then
  50.         local ok, err = pcall(msg:sub(6))
  51.         if not ok then
  52.             chatbox.tell(player, "Error: "..err)
  53.         else
  54.             chatbox.tell(player, "Result: "..err)
  55.         end
  56.     end
  57. end
  58.  
  59. repeat
  60.     e, side, user, msg = os.pullEvent("chat_message")
  61.     if whitelist[user] and msg:sub(1,#prefix) == prefix then
  62.         RunCommand(msg:sub(#prefix+1), user)
  63.     end
  64. until e == "char" and side == keys.q
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement