#! /usr/bin/env lua
local commands = {}
function trim(s)
return s:match("^%s*(.-)%s*$")
end
function rtrim(s)
return s:gsub("%s+$", "")
end
function string.starts(String,Start)
return string.sub(String, 1, string.len(Start)) == Start
end
function mcbot_register_command (name, object)
commands[name] = object
end
function mcbot_get_command_list ()
return commands
end
require "cmds.help"
require "cmds.wtf"
require "cmds.calc"
require "cmds.spell"
require "cmds.dict"
require "cmds.misc"
require "cmds.xep"
require "cmds.mcabber_bts"
require "cmds.bofh"
function process (line, botdata, muc)
local n
line = trim(line)
line, n = line:gsub("^"..botdata.nickname.."[,: ]%s+", "")
if muc and n ~= 1 then return nil, nil end
local cmd, arg
cmd = line:match("^(%w+)%s*[!]*$")
if not cmd then
-- Check if there are arguments
cmd, arg = line:match("^(%w+)%s+(.*)")
end
if cmd then
local lccmd = cmd:lower()
for name, obj in pairs(commands) do
if lccmd == name then
return obj.cmd(arg, botdata, cmd)
end
if obj.aliases then
for i, alias in ipairs(obj.aliases) do
if lccmd == alias then
return obj.cmd(arg, botdata, cmd)
end
end
end
end
else
-- Ignore smileys
if line:match("^[:;8]'?%-?[D()|/\\%[%]pPoO$@]+%s*$") then return nil,nil end
if line:match("^^^%s*$") then return nil,nil end
end
return "I don't understand, Sir"
end