Advertisement
SirBaconBitz

Anime character bot...

Aug 26th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.05 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 = "Gandalf"
  11. local host = "na.irc.esper.net:6667"
  12. local pass = "imnotabot"
  13. local chan = "#beyondreality"
  14. local nametop = 2400
  15.  
  16. local ver_maj = 0
  17. local ver_min = 1
  18. local ver_rev = 1
  19. local ver = ver_maj.."."..ver_min.."."..ver_rev
  20.  
  21. local nametab = {"Edward_Elric", "Alphonse_Elric", "Albus_Dumbledore", "Harry_Potter", "Lelouch_Vi_Britannia", "Hatsune_Miku", "Spike_Spiegel", "Kamina", "Light_Yagami", "Kirito", "Asuna", "Eren_Yeager", "Tasumi", "Akame", "Mine", "Leone", "Sheele", "Inaho", "Slaine", "Asseylum",
  22. "Alucard", "Seras_Victoria", "Rin_Okumura", "Yukio_Okumura", "Monkey_D._Luffy", "Saber", "Lancer", "Archer", "Gilgamesh", "Caster", "Berserker", "Assassin", "Natsu_Dragneel", "Happy", "Lucy", "Gray", "Erza", "Wendy", "Gajeel", "Meliodas", "Naruto", "Sakura", "Sasuke", "Kakashi",
  23. "Kakashi", "Madara", "Obito", "Sage_of_Six_Paths", "Mustang", "Lt. Hawkeye", "Envy", "Greed", "Lust", "Wrath", "Pride", "Gluttony", "Celty", "Vash_the_Stampede", "Shiroe", "Naotsugu", "Akatsuki", "Nyanta", "Crusty", "Yuno_Gasai", "Akane_Tsunemori", "Shinya_Kogami", "Nobuchika_Ginoza",
  24. "Rintaro_Okabe", "Kurisu_Makise", "Suzaku_Kururugi", "Ryuk", "L", "C.C", "Yusuke_Urameshi", "Kazuma_Kuwabara", "Kurama", "Hiei", "Genkai", "Hakurei_Reimu", "Kirisame_Marisa", "Patchoulu_Knowledge", "Flandre_Scarlet", "Remilia_Scarlet", "Birdy_Cephon", "Tsutomu_Senkawa", "Soul", "Death_the_Kid",
  25. "Rikka_Takanashi", "Gundam"}
  26.  
  27. if not component.isAvailable("internet") then
  28.   io.stderr:write("You forgot the internet card you dumbfuck")
  29.   return
  30. end
  31.  
  32. local sock, err = internet.open(host)
  33.  
  34. if not sock then
  35.   io.stderr:write(err .. "\n")
  36.   return
  37. end
  38.  
  39. sock:setTimeout(0.05)
  40. sock:write(string.format("PASS %s\r\n", pass))
  41. sock:write(string.format("NICK %s\r\n", nick))
  42. sock:write(string.format("USER %s 0 * :%s [OpenComputers]\r\n", nick:lower(), nick))
  43. sock:flush()
  44.  
  45. function changename()
  46.     local newname = nametab[math.random(#nametab)]
  47.     computer.beep()
  48.     sock:write(string.format("NICK %s\r\n", newname))
  49.     sock:flush()
  50. end
  51.  
  52. timer = event.timer(0.5, function()
  53.   local okrep = 0
  54.   if not sock then return false end
  55.   repeat
  56.     local ok, line = pcall(sock.read, sock)
  57.     if not ok then okrep = okrep + 1 end
  58.     if ok and line then
  59.       print(line)
  60.       if line:find("PING") then
  61.         print("Received PING")
  62.         local pongnum = line:sub(6)
  63.         resp = "PONG "..pongnum
  64.         print(resp)
  65.         sock:write(resp)
  66.         sock:flush()
  67.       end
  68.     end
  69.   until okrep == 75
  70. end)
  71.  
  72. os.sleep(10)
  73. print("Attempting to join")
  74. sock:write(string.format("JOIN %s\r\n", chan))
  75. sock:flush()
  76. os.sleep(2)
  77. sock:write("PRIVMSG expert700 :Exbot ["..ver.."] is online\r\n")
  78. sock:flush()
  79.  
  80. timer = event.timer(0.5, function()
  81.   local namerep = 2375
  82.   if not sock then return false end
  83.   while true do
  84.     namerep = namerep + 1
  85.     local ok, line = pcall(sock.read, sock)
  86.     if ok and line then
  87.       print(line)
  88.       if line:find("PING") then
  89.         print("Received PING")
  90.         local pongnum = line:sub(6)
  91.         resp = "PONG "..pongnum
  92.         print(resp)
  93.         sock:write(resp)
  94.         sock:flush()
  95.       end
  96.       if line:find("␁") then
  97.         print("CTCP")
  98.       elseif line:find("!newname") then
  99.         changename()
  100.       elseif line:find("!setint") then
  101.         local valmsg = nil
  102.         for half in string.gmatch(line, '([^:]+)') do
  103.           if half:find("!setint") then
  104.             valmsg = half
  105.           end
  106.         end
  107.         for v in string.gmatch(valmsg, "%S+") do
  108.           if not v:find("!setint") then
  109.             nametop = tonumber(v)
  110.             computer.beep()
  111.           end
  112.         end
  113.       end
  114.     end
  115.     if namerep >= nametop then
  116.       computer.beep()
  117.       os.sleep(0.25)
  118.       computer.beep()
  119.       namerep = 0
  120.       changename()
  121.     end
  122.   end
  123. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement