mcbot/cmds/bofh.lua
author Mikael Berthe <mikael@lilotux.net>
Thu, 15 Apr 2010 21:47:33 +0200
changeset 23 491f7d046353
child 67 5c756a9d7d8c
permissions -rw-r--r--
Add command bofh :-)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23
491f7d046353 Add command bofh :-)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     1
491f7d046353 Add command bofh :-)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     2
local excusefile = "/home/mikael/.mcabber/lua/mcbot/bofh_excuses.txt"
491f7d046353 Add command bofh :-)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     3
491f7d046353 Add command bofh :-)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     4
local bofh = { ["desc"] = "Give a BOFH excuse",
491f7d046353 Add command bofh :-)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     5
               ["aliases"] = { "excuse" } }
491f7d046353 Add command bofh :-)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     6
491f7d046353 Add command bofh :-)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     7
function bofh.cmd (args, botdata, cmd)
491f7d046353 Add command bofh :-)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     8
    local r = {}
491f7d046353 Add command bofh :-)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     9
    if cmd:lower() == "excuse" and args and not args:match("[!%?]+") then
491f7d046353 Add command bofh :-)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    10
        return nil
491f7d046353 Add command bofh :-)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    11
    end
491f7d046353 Add command bofh :-)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    12
    for line in io.lines(excusefile) do table.insert(r, line) end
491f7d046353 Add command bofh :-)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    13
    local len = table.getn(r)
491f7d046353 Add command bofh :-)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    14
    if len == 0 then
491f7d046353 Add command bofh :-)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    15
        return nil, "I have no excuse, Sir...  :-("
491f7d046353 Add command bofh :-)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    16
    end
491f7d046353 Add command bofh :-)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    17
    local n = math.random(len)
491f7d046353 Add command bofh :-)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    18
    return "BOFH's excuse: "..r[n]
491f7d046353 Add command bofh :-)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    19
end
491f7d046353 Add command bofh :-)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    20
491f7d046353 Add command bofh :-)
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    21
mcbot_register_command("bofh", bofh)