test_irc.lua 755 B

123456789101112131415161718192021222324252627282930313233343536
  1. mooni2p = require("mooni2p")
  2. local session_sock = assert(mooni2p.create_session("irctest", "TRANSIENT"))
  3. local sock = assert(mooni2p.stream_connect("irctest", "irc.ilita.i2p"))
  4. sock:send("NICK luabot\n")
  5. sock:send("USER luabot luabot luabot :luabot\n")
  6. while 1 do
  7. data = sock:receive("*l")
  8. if #data == 0 then
  9. print("connection closed")
  10. break
  11. else
  12. print(pdata)
  13. if data:sub(1, 6) == "PING :" then
  14. pdata = data:sub(7, -1)
  15. sock:send("PONG :" .. pdata .. "\n")
  16. else
  17. if data:sub(1,1) == ":" then
  18. local words = mooni2p._split(data)
  19. if words[2] == "422" or words[2] == "376" then
  20. sock:send("JOIN #ru\n")
  21. end
  22. end
  23. end
  24. if string.find(data, "STOP BOT") then
  25. break
  26. end
  27. end
  28. end
  29. sock:close()
  30. session_sock:close()