]> git.lizzy.rs Git - luairc.git/commitdiff
start changing things over from testing for type (string/table) to find ctcp messages...
authorjluehrs2 <jluehrs2@uiuc.edu>
Tue, 4 Sep 2007 20:08:37 +0000 (15:08 -0500)
committerjluehrs2 <jluehrs2@uiuc.edu>
Tue, 4 Sep 2007 20:08:37 +0000 (15:08 -0500)
src/irc.lua
src/irc/ctcp.lua

index 761039b45e331fcb3d976aa7ce54f7dc23686265..9376efd3ffb2f98b8f962b844942a6254509aea4 100644 (file)
@@ -227,19 +227,10 @@ end
 function handlers.on_privmsg(from, to, msg)
     local msgs = ctcp._ctcp_split(msg)
     for _, v in base.ipairs(msgs) do
-        if base.type(v) == "string" then
-            -- normal message {{{
-            if to:sub(1, 1) == "#" then
-                base.assert(serverinfo.channels[to],
-                            "Received channel msg from unknown channel: " .. to)
-                misc._try_call(on_channel_msg, serverinfo.channels[to], from, v)
-            else
-                misc._try_call(on_private_msg, from, v)
-            end
-            -- }}}
-        elseif base.type(v) == "table" then
+        local msg = v.str
+        if v.ctcp then
             -- ctcp message {{{
-            local words = misc._split(v[1])
+            local words = misc._split(msg)
             local received_command = words[1]
             local cb = "on_" .. received_command:lower()
             table.remove(words, 1)
@@ -251,6 +242,17 @@ function handlers.on_privmsg(from, to, msg)
                 notice(from, {"ERRMSG Unknown query: " .. received_command})
             end
             -- }}}
+        else
+            -- normal message {{{
+            if to:sub(1, 1) == "#" then
+                base.assert(serverinfo.channels[to],
+                            "Received channel msg from unknown channel: " .. to)
+                misc._try_call(on_channel_msg, serverinfo.channels[to], from,
+                                               msg)
+            else
+                misc._try_call(on_private_msg, from, msg)
+            end
+            -- }}}
         end
     end
 end
@@ -260,26 +262,27 @@ end
 function handlers.on_notice(from, to, msg)
     local msgs = ctcp._ctcp_split(msg)
     for _, v in base.ipairs(msgs) do
-        if base.type(v) == "string" then
+        local msg = v.str
+        if v.ctcp then
+            -- ctcp message {{{
+            local words = misc._split(msg)
+            local command = words[1]:lower()
+            table.remove(words, 1)
+            misc._try_call_warn("Unknown CTCP message: " .. command,
+                                ctcp_handlers["on_rpl_"..command], from, to,
+                                table.concat(words, ' '))
+            -- }}}
+        else
             -- normal message {{{
             if to:sub(1, 1) == "#" then
                 base.assert(serverinfo.channels[to],
                             "Received channel msg from unknown channel: " .. to)
                 misc._try_call(on_channel_notice, serverinfo.channels[to],
-                               from, v)
+                               from, msg)
             else
-                misc._try_call(on_private_notice, from, v)
+                misc._try_call(on_private_notice, from, msg)
             end
             -- }}}
-        elseif base.type(v) == "table" then
-            -- ctcp message {{{
-            local words = misc._split(v[1])
-            local command = words[1]:lower()
-            table.remove(words, 1)
-            misc._try_call_warn("Unknown CTCP message: " .. command,
-                                ctcp_handlers["on_rpl_"..command], from, to,
-                                table.concat(words, ' '))
-            -- }}}
         end
     end
 end
index 18661221562667ed0ee931ff074d586cc039f11f..5848416411cf8a4c79837dcecebeb932510cbe5a 100644 (file)
@@ -71,13 +71,17 @@ end
 -- }}}
 
 -- _ctcp_split {{{
--- TODO: again with this string/table thing... it's ugly!
 --
 -- Splits a low level dequoted string into normal text and unquoted CTCP
 -- messages.
 -- @param str Low level dequoted string
--- @return Array, where string values correspond to plain text, and table
---         values have t[1] as the CTCP message
+-- @return Array of tables, with each entry in the array corresponding to one
+--         part of the split message. These tables will have these fields:
+--         <ul>
+--         <li><i>str:</i>  The text of the split section</li>
+--         <li><i>ctcp:</i> True if the section was a CTCP message, false
+--                          otherwise</li>
+--         </ul>
 function _ctcp_split(str)
     local ret = {}
     local iter = 1
@@ -93,11 +97,11 @@ function _ctcp_split(str)
         end
 
         if plain_string ~= "" then
-            table.insert(ret, plain_string)
+            table.insert(ret, {str = plain_string, ctcp = false})
         end
         if not s then break end
         if ctcp_string ~= "" then
-            table.insert(ret, {_ctcp_dequote(ctcp_string)})
+            table.insert(ret, {str = _ctcp_dequote(ctcp_string), ctcp = true})
         end
 
         iter = e + 1