Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Simple Read-Only IRC Bot by expert700
- local component = require("component")
- local computer = require("computer")
- local event = require("event")
- local internet = require("internet")
- local shell = require("shell")
- local term = require("term")
- local nick = "Exbot"
- local host = "na.irc.esper.net:6667"
- local pass = "imnotabot"
- local chan = "#42"
- local ver_maj = 0
- local ver_min = 1
- local ver_rev = 1
- local ver = ver_maj.."."..ver_min.."."..ver_rev
- if not component.isAvailable("internet") then
- io.stderr:write("You forgot the internet card you dumbfuck")
- return
- end
- local sock, err = internet.open(host)
- if not sock then
- io.stderr:write(err .. "\n")
- return
- end
- sock:setTimeout(0.05)
- sock:write(string.format("PASS %s\r\n", pass))
- sock:write(string.format("NICK %s\r\n", nick))
- sock:write(string.format("USER %s 0 * :%s [OpenComputers]\r\n", nick:lower(), nick))
- sock:flush()
- -- sock:write(string.format("JOIN %s\r\n", chan))
- timer = event.timer(0.5, function()
- local okrep = 0
- if not sock then return false end
- repeat
- local ok, line = pcall(sock.read, sock)
- if not ok then okrep = okrep + 1 end
- if ok and line then
- print(line)
- if line:find("PING") then
- print("Received PING")
- local pongnum = line:sub(6)
- resp = "PONG "..pongnum
- print(resp)
- sock:write(resp)
- sock:flush()
- end
- end
- until okrep == 75
- end)
- os.sleep(10)
- print("Attempting to join")
- sock:write(string.format("JOIN %s\r\n", chan))
- sock:flush()
- os.sleep(2)
- sock:write("PRIVMSG expert700 :Exbot ["..ver.."] is online\r\n")
- sock:flush()
- timer = event.timer(0.5, function()
- if not sock then return false end
- while true do
- local ok, line = pcall(sock.read, sock)
- if ok and line then
- print(line)
- if line:find("PING") then
- print("Received PING")
- local pongnum = line:sub(6)
- resp = "PONG "..pongnum
- print(resp)
- sock:write(resp)
- sock:flush()
- end
- if line:find("␁") then
- print("CTCP")
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement