Advertisement
SirBaconBitz

Lua Socket Bot

Sep 30th, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.45 KB | None | 0 0
  1. --LuaSocket IRC Bot by Expert700
  2.  
  3. local socket = require("socket")
  4. __DEBUG = true
  5.  
  6. local nick = "Au"
  7. local host = "na.irc.esper.net"
  8. local pass = "imnotabot"
  9. local chan = "#OTEGamers"
  10. local nametop = 2400
  11.  
  12. local ver_maj = 0
  13. local ver_min = 1
  14. local ver_rev = 1
  15. local ver = ver_maj.."."..ver_min.."."..ver_rev
  16.  
  17. 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",
  18. "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",
  19. "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",
  20. "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",
  21. "Rikka_Takanashi", "Gundam"}
  22.  
  23. function sleep(n)
  24.   os.execute("timeout " .. tonumber(n))
  25. end
  26.  
  27. local client = assert(socket.connect("na.irc.esper.net", 6667))
  28.  
  29. client:settimeout(1)
  30. client:send(string.format("PASS %s\r\n", pass))
  31. client:send(string.format("NICK %s\r\n", nick))
  32. client:send(string.format("USER %s 0 * :%s [OpenComputers]\r\n", nick:lower(), nick))
  33.  
  34. function changename()
  35.     local newname = nametab[math.random(#nametab)]
  36.     client:send(string.format("NICK %s\r\n", newname))
  37. end
  38.  
  39.  
  40. local okrep = 0
  41. repeat
  42.   print(okrep)
  43.   local line, ok = client:receive()
  44.   if ok then okrep = okrep + 1 end
  45.   if not 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.       client:send(resp)
  53.     end
  54.   end
  55.   if okrep == 20 then
  56.     client:send(string.format("JOIN %s\r\n", chan))
  57.   end
  58. until okrep == 30
  59.  
  60. print("Waiting to join")
  61. sleep(10)
  62. print("Attempting to join")
  63. client:send(string.format("JOIN %s\r\n", chan))
  64. sleep(2)
  65. client:send("PRIVMSG expert700 :Exbot ["..ver.."] is online\r\n")
  66.  
  67.  
  68.  
  69. local namerep = 5000
  70. while true do
  71.   namerep = namerep + 1
  72.   local line, ok = client:receive()
  73.   if not ok and line then
  74.     print(line)
  75.     if line:find("PING") then
  76.       print("Received PING")
  77.       local pongnum = line:sub(6)
  78.       resp = "PONG "..pongnum
  79.       print(resp)
  80.       client:send(resp)
  81.     end
  82.     if line:find("␁") then
  83.       print("CTCP")
  84.     elseif line:find("!newname") then
  85.       changename()
  86.     elseif line:find("!setint") then
  87.       local valmsg = nil
  88.       for half in string.gmatch(line, '([^:]+)') do
  89.         if half:find("!setint") then
  90.           valmsg = half
  91.         end
  92.       end
  93.       for v in string.gmatch(valmsg, "%S+") do
  94.         if not v:find("!setint") then
  95.           nametop = tonumber(v)
  96.         end
  97.       end
  98.     end
  99.   end
  100.   if namerep >= nametop then
  101.     sleep(0.25)
  102.     namerep = 0
  103.     changename()
  104.   end
  105. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement