plugins.xkcd: Exact matches takes priority over others

Wed, 09 Mar 2011 18:04:36 +0100

author
Kim Alvefur <zash@zash.se>
date
Wed, 09 Mar 2011 18:04:36 +0100
changeset 65
25f4445447b2
parent 64
a317a5d4340c
child 66
bdaf81ab55ad

plugins.xkcd: Exact matches takes priority over others

plugins/xkcd.lua file | annotate | diff | comparison | revisions
--- a/plugins/xkcd.lua	Mon Feb 21 16:50:03 2011 +0100
+++ b/plugins/xkcd.lua	Wed Mar 09 18:04:36 2011 +0100
@@ -37,12 +37,15 @@
 		if not xkcdnum then return "Please supply an XKCD number or a search string :)"; end
 			if not tonumber(xkcdnum) then -- Search for an xkcd
 				xkcdnum = xkcdnum:gsub("[()]", function(s) return "%" .. s end)
+					:lower()
 					:gsub("[%[]",function(s) return "%" .. s end)
 					:gsub("%%(%b[])",function(s) return (#s > 2 and "" or "%") .. s end);
 				local results = {};
 				for x, xkcd in pairs(xkcd_list) do
 					name = xkcd:lower()
-					if name:match(xkcdnum:lower()) then
+					if name == xkcdnum then -- exact match
+						return xkcd..", http://xkcd.org/"..x.."/";
+					elseif name:match(xkcdnum) then
 						table.insert(results, x);
 						--return commands.xkcd(msg, x);
 					end

mercurial