mcbot/cmds/wtf.lua
author Mikael Berthe <mikael@lilotux.net>
Tue, 27 Nov 2012 16:36:17 +0100
changeset 67 5c756a9d7d8c
parent 66 d9c00a9fe9d5
permissions -rw-r--r--
Quick'n dirty hack to remove hardcoded paths


--  This module is part of the McBot / mcabbot project
--  What-The-F... module.
--
-- Copyright (C) 2010-2012 Mikael Berthe <mikael@lilotux.net>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or (at
-- your option) any later version.
--
-- Please check the license in the COPYING file at the root of the tree.
--

local home = os.getenv("HOME")
local wtfdbfile = home.."/.mcabber/mcabbot/mcbot/wtfdb.txt"
home = nil

local wtf = { ["desc"] = "Acronym dictionary" }

function wtf.cmd (args)
    local r = {}
    if not args then return nil, "WTH do you want?" end
    args = args:gsub("[%s%?%.%!]+$", ""):upper()
    for line in io.lines(wtfdbfile) do
        if line:starts(args.."\t") then
            table.insert(r, line)
        end
    end
    local len = table.getn(r)
    if len == 0 then
        return nil, "I don't know, Sir"
    end
    local strresult = r[1]
    for i = 2, len do
        strresult = strresult .. "\n" .. r[i]
    end
    return strresult
end

mcbot_register_command("wtf", wtf)