--- -- Implementation of IRC server message parsing -- initialization {{{ local constants = libs.constants local ctcp = libs.ctcp local irc_debug = libs.debug local misc = libs.misc local socket = libs.socket -- }}} --- -- This module contains parsing functions for IRC server messages. local message = {} -- internal functions {{{ -- _parse {{{ -- -- Parse a server command. -- @param str Command to parse -- @return Table containing the parsed message. It contains: -- function message._parse(str) -- low-level ctcp quoting {{{ str = ctcp._low_dequote(str) -- }}} -- parse the from field, if it exists (leading :) {{{ local from = "" if str:sub(1, 1) == ":" then local e e, from = socket.skip(1, str:find("^:([^ ]*) ")) str = str:sub(e + 1) end -- }}} -- get the command name or numerical reply value {{{ local command, argstr = socket.skip(2, str:find("^([^ ]*) ?(.*)")) local reply = false if command:find("^%d%d%d$") then reply = true if constants.replies[tonumber(command)] then command = constants.replies[tonumber(command)] else irc_debug._warn("Unknown server reply: " .. command) end end -- }}} -- get the args {{{ local args = misc._split(argstr, " ", ":") -- the first arg in a reply is always your nick if reply then table.remove(args, 1) end -- }}} -- return the parsed message {{{ return {from = from, command = command, args = args} -- }}} end -- }}} -- }}} return message