All pastes #816643 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-12-14 22:09 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
   end
end

function 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 ret
end

socket = require("socket")

-- Connect to IRC, make sure the nick is free, give IRC our credentials

print("Connecting to IRC...")
socket = socket.connect("irc.ascentemu.com",6667)
socket:send("PRIVMSG NickServ :ghost LuaBOT panstarefun\n")
socket:send("NICK BurkBOT\n")
socket:send("USER BurkBOT 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;
    end
until ( trip == true)

-- End of the intro crap, we now deliver the nick ID command

print("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")
    end
until (count == nil)