All pastes #766389 Raw Edit

Moldy

public lua v1 · immutable
·published 2007-11-08 21:02 UTC
rendered paste body
local function regexp(string, exp)   local ret   string.gsub(string, exp, function(...) ret = arg end)   if(ret) then      return unpack(ret)   else      return nil   endendfunction parseline(line)   local nl   local prefix,command   prefix,ln = regexp(line, "^%:([^ ]+) +(.+)$")   if(prefix) then line = ln end   command,ln = regexp(line, "^([^ ]+)(.*)$")   if(not command) then      command,ln = regexp(line, "^([0-9][0-9][0-9])( +.+)$")      if(not command) then return nil end   else      if(string.gsub(command, "[^-A-Za-z0-9_]", "") ~= command) then return nil end   end   line = ln   local ret = {prefix=prefix, command=command}   repeat      local param      param,ln = regexp(line, "^ +([^:\10\13 ][^\10\13 ]*)(.*)$")      if(not param) then	 param = regexp(line, "^ +:([^\10\13]*)$")	 if(not param) then	    return ret	 end	 table.insert(ret, param)	 return ret      else	 table.insert(ret, param)	 line = ln      end   until false   return retendsocket = require("socket")-- Connect to IRC, make sure the nick is free, give IRC our credentialsprint("Connecting to IRC...")socket = socket.connect("irc.ascentemu.com",6667)socket:send("PRIVMSG NickServ :ghost LuaBOT panstarefun\n")socket:send("NICK LuaBOT\n")socket:send("USER LuaBOT bogus. this.is.ignored :CDC\n")-- [[ Display all the crap IRC sends back; we're looking for the PING and for the moment to ID the nick. When we find the PING we PONG back. A debugging line allows us to see what commands we're getting from the IRC server. ]]trip = false;repeat    feedback = socket:receive("*l")    print(feedback)    cmd = parseline(feedback)--  printtable(cmd)    if (cmd["command"] == "PING") then        print("Found PING!!!")        socket:send("PONG "..cmd[1].."\n")		trip = true;    enduntil ( trip == true)-- End of the intro crap, we now deliver the nick ID commandprint("Sending IDENTIFY command.")socket:send("PRIVMSG NickServ :IDENTIFY pantsarefun\n")feedback = socket:receive("*l")print(feedback)-- We're now connected, and enter #cdc on command-- io.input()print("Connected. Ready to join the channel")x = io.read("*l")print(x)socket:send("JOIN #moon++\n")count = 0;repeat    feedback = socket:receive("*l")    print(feedback)    cmd = parseline(feedback)--  printtable(cmd)    if (cmd["command"] == "PING") then        print("Ponging!!!")        socket:send("PONG "..cmd[1].."\n")    enduntil (count == nil)