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