3 local constants = require 'irc.constants'
4 local ctcp = require 'irc.ctcp'
5 local irc_debug = require 'irc.debug'
6 local misc = require 'irc.misc'
7 local socket = require 'socket'
8 local string = require 'string'
9 local table = require 'table'
14 -- local functions {{{
15 -- parse() - parse a server command {{{
17 -- low-level ctcp quoting {{{
18 str = ctcp.low_dequote(str)
20 -- parse the from field, if it exists (leading :) {{{
22 if str:sub(1, 1) == ":" then
24 e, from = socket.skip(1, str:find("^:([^ ]*) "))
28 -- get the command name or numerical reply value {{{
29 local command, argstr = socket.skip(2, str:find("^([^ ]*) ?(.*)"))
31 if command:find("^%d%d%d$") then
33 if constants.replies[base.tonumber(command)] then
34 command = constants.replies[base.tonumber(command)]
36 irc_debug.warn("Unknown server reply: " .. command)
41 local args = misc.split(argstr, " ", ":")
42 -- the first arg in a reply is always your nick
43 if reply then table.remove(args, 1) end
45 -- return the parsed message {{{
46 return {from = from, command = command, args = args}