# HG changeset patch # User Mikael Berthe # Date 1271511849 -7200 # Node ID a166e9ab8065f80d18355a843701f6f6e90e5045 # Parent c12be727375b6eb07e312ef684e8868d7dc5fe2d Add command prefix (useful for MUC rooms) diff -r c12be727375b -r a166e9ab8065 mcabbot.lua --- a/mcabbot.lua Sat Apr 17 15:33:23 2010 +0200 +++ b/mcabbot.lua Sat Apr 17 15:44:09 2010 +0200 @@ -10,6 +10,7 @@ local mcabbot = {} mcabbot.nickname = "McBot" mcabbot.jid = "mcabbot@lilotux.net" +mcabbot.cmdprefix = "%%" local function hk_subscription (h) if h.type == "subscribe" then @@ -50,7 +51,7 @@ cmd = "say_to -q "..h.jid.."/"..h.resource.." " end mcabbot.message = h - local res, errmsg = process(message, mcabbot, muc) + local res, errmsg = process(message, mcabbot, muc, mcabbot.cmdprefix) mcabbot.message = nil if res then msg = res diff -r c12be727375b -r a166e9ab8065 mcbot/mcbot_engine.lua --- a/mcbot/mcbot_engine.lua Sat Apr 17 15:33:23 2010 +0200 +++ b/mcbot/mcbot_engine.lua Sat Apr 17 15:44:09 2010 +0200 @@ -9,7 +9,7 @@ return s:gsub("%s+$", "") end -function string.starts(String,Start) +function string.starts(String, Start) return string.sub(String, 1, string.len(Start)) == Start end @@ -32,11 +32,18 @@ require "cmds.bofh" require "cmds.xmpp" -function process (line, botdata, muc) +function process (line, botdata, muc, cmdprefix) local n line = trim(line) line, n = line:gsub("^"..botdata.nickname.."[,:]?%s+", "") - if muc and n ~= 1 then return nil, nil end + if muc and n ~= 1 then + if cmdprefix and line:starts(cmdprefix) then + line = line:sub(string.len(cmdprefix)+1) + line = line:gsub("^%s*", "") + else + return nil, nil + end + end local cmd, arg cmd = line:match("^(%w+)%s*[!]*$")