# HG changeset patch # User Kim Alvefur # Date 1370019692 -7200 # Node ID 4234c8789cc6e2e341f641f9f8844914ecdda50a # Parent 8202cdfb99b4e79abfdad629d211dedd41abda0c plugins.{ping,version,resolvejid}: Break nickname/jid resolving into a common plugin diff -r 8202cdfb99b4 -r 4234c8789cc6 plugins/ping.lua --- a/plugins/ping.lua Sat May 25 23:21:30 2013 +0200 +++ b/plugins/ping.lua Fri May 31 19:01:32 2013 +0200 @@ -1,9 +1,11 @@ function riddim.plugins.ping(bot) bot.stream:add_plugin("ping"); + bot:add_plugin("resolvejid"); bot:hook("commands/ping", function (command) local jid = command.param; if jid then + jid = bot:resolvejid(jid, command.room); bot.stream:ping(jid, function (time, jid, error) if time then command:reply(string.format("Pong from %s in %0.3f seconds", jid, time)); diff -r 8202cdfb99b4 -r 4234c8789cc6 plugins/resolvejid.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/resolvejid.lua Fri May 31 19:01:32 2013 +0200 @@ -0,0 +1,13 @@ +function riddim.plugins.resolvejid(bot) + function bot:resolvejid(jid, room) + local nows = jid:match"%S+" + local trimd = jid:match"^%s*(.-)%s*$" + if room then + local occupant = room.occupants[jid] + or room.occupants[trimd] + or room.occupants[nows] + if occupant then return occupant.jid end + end + return nows + end +end diff -r 8202cdfb99b4 -r 4234c8789cc6 plugins/version.lua --- a/plugins/version.lua Sat May 25 23:21:30 2013 +0200 +++ b/plugins/version.lua Fri May 31 19:01:32 2013 +0200 @@ -10,16 +10,11 @@ platform = bot.config.bot_platform or _VERSION; }; + bot:add_plugin("resolvejid"); bot:hook("commands/version", function (command) local who, param = bot.stream.jid, command.param; if param then - if command.room and command.room.occupants[param] then - who = command.room.occupants[param].jid; - elseif command.room and command.room.occupants[param:gsub("%s$", "")] then - who = command.room.occupants[param:gsub("%s$", "")].jid; - else - who = param; - end + who = bot:resolvejid(param, command.room); end bot.stream:query_version(who, function (reply) diff -r 8202cdfb99b4 -r 4234c8789cc6 squishy --- a/squishy Sat May 25 23:21:30 2013 +0200 +++ b/squishy Fri May 31 19:01:32 2013 +0200 @@ -5,6 +5,7 @@ Module "riddim.plugins.ping" "plugins/ping.lua" Module "riddim.plugins.tell" "plugins/tell.lua" Module "riddim.plugins.uptime" "plugins/uptime.lua" +Module "riddim.plugins.resolvejid" "plugins/resolvejid.lua" Main "init.lua"