Advertisement
SirBaconBitz

Bot

Jul 25th, 2015
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.21 KB | None | 0 0
  1. -- Simple Read-Only IRC Bot by expert700
  2.  
  3. local component = require("component")
  4. local computer = require("computer")
  5. local event = require("event")
  6. local internet = require("internet")
  7. local shell = require("shell")
  8. local term = require("term")
  9.  
  10. local nick = "Exbot"
  11. local host = "na.irc.esper.net:6667"
  12. local pass = "imnotabot"
  13. local chan = "#TPPI"
  14.  
  15. local ver_maj = 0
  16. local ver_min = 1
  17. local ver_rev = 1
  18. local ver = ver_maj.."."..ver_min.."."..ver_rev
  19.  
  20. if not component.isAvailable("internet") then
  21.   io.stderr:write("You forgot the internet card you dumbfuck")
  22.   return
  23. end
  24.  
  25. local sock, err = internet.open(host)
  26.  
  27. if not sock then
  28.   io.stderr:write(err .. "\n")
  29.   return
  30. end
  31.  
  32. sock:setTimeout(0.05)
  33. sock:write(string.format("PASS %s\r\n", pass))
  34. sock:write(string.format("NICK %s\r\n", nick))
  35. sock:write(string.format("USER %s 0 * :%s [OpenComputers]\r\n", nick:lower(), nick))
  36. sock:flush()
  37. -- sock:write(string.format("JOIN %s\r\n", chan))
  38.  
  39. timer = event.timer(0.5, function()
  40.   local okrep = 0
  41.   if not sock then return false end
  42.   repeat
  43.     local ok, line = pcall(sock.read, sock)
  44.     if not ok then okrep = okrep + 1 end
  45.     if ok and line then
  46.       print(line)
  47.       if line:find("PING") then
  48.         print("Received PING")
  49.         local pongnum = line:sub(6)
  50.         resp = "PONG "..pongnum
  51.         print(resp)
  52.         sock:write(resp)
  53.         sock:flush()
  54.       end
  55.     end
  56.   until okrep == 75
  57. end)
  58.  
  59. os.sleep(10)
  60. print("Attempting to join")
  61. sock:write(string.format("JOIN %s\r\n", chan))
  62. sock:flush()
  63. os.sleep(2)
  64. sock:write("PRIVMSG expert700 :Exbot ["..ver.."] is online\r\n")
  65. sock:flush()
  66.  
  67. timer = event.timer(0.5, function()
  68.   if not sock then return false end
  69.   while true do
  70.     local ok, line = pcall(sock.read, sock)
  71.     if ok and line then
  72.       print(line)
  73.       if line:find("PING") then
  74.         print("Received PING")
  75.         local pongnum = line:sub(6)
  76.         resp = "PONG "..pongnum
  77.         print(resp)
  78.         sock:write(resp)
  79.         sock:flush()
  80.         sock:write("PRIVMSG TPPI :Join a gr8/8 TPPI server at otegamers.com m8\r\n")
  81.         sock:flush()
  82.       end
  83.       if line:find("␁") then
  84.         print("CTCP")
  85.       end
  86.     end
  87.   end
  88. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement