-- AntiReg by Madman
-- On request by Q??K, 21.01.06
-- Added: Showall cmd, 25.01.06
Bot = "AntiReg"
File = "AntiReg.txt"
-- Cmd's
NoReReg = "norereg"
ShowNoReReg = "shownorereg"
ShowAll = "showall"
function Main()
frmHub:RegBot(Bot)
local file = io.open(File)
if file then
file:close()
else
local file = io.open(File, "w+")
file:write("AntiReg = {\n}")
file:close()
end
LoadFromFile(File)
end
function ChatArrival(curUser, data)
local data = string.sub(data, 1, -2)
local s,e,prfx,cmd = string.find(data, "%b<>%s+(%p)(%S+)")
if cmd and curUser.bOperator then
local tCmds = {
[NoReReg] = function(curUser, data)
local s,e,Nick,Reason = string.find(data, "%b<>%s+%S+%s+(%S+)%s+(.+)")
if Nick and Reason then
Nick = string.lower(Nick)
if AntiReg[Nick] == nil then
AntiReg[Nick] = {}
AntiReg[Nick]["Reason"] = {}
AntiReg[Nick]["AddBy"] = {}
AntiReg[Nick]["Reason"] = Reason
AntiReg[Nick]["AddBy"] = curUser.sName
curUser:SendData(Bot, Nick.. " has been added with reason: " ..Reason)
SaveToFile(File, AntiReg, "AntiReg") return 1
else
curUser:SendData(Bot, Nick.. " was allready in the table with the reason: " ..AntiReg[Nick]["Reason"].. " added by " ..AntiReg[Nick]["AddBy"])
end
end
curUser:SendData(Bot, "Syntax: "..prfx..cmd.. " <Nick> <Reason>") return 1
end,
[ShowNoReReg] = function(curUser, data)
local s,e,Nick = string.find(data, "%b<>%s+%S+%s+(%S+)")
if Nick then
Nick = string.lower(Nick)
if AntiReg[Nick] == nil then
curUser:SendData(Bot, Nick.. " is not in the list") return 1
else
curUser:SendData(Bot, Nick.. " is in the list with the reason: " ..AntiReg[Nick]["Reason"].. " addded by " ..AntiReg[Nick]["AddBy"]) return 1
end
else
curUser:SendData(Bot, "Syntax: "..prfx..cmd.. " <Nick>") return 1
end
end,
[ShowAll] = function(curUser, data)
for i,_ in AntiReg do
curUser:SendPM(Bot, "Nick: " ..i.. " added by: " ..AntiReg[i]["AddBy"].. " with the reason: " ..AntiReg[i]["Reason"])
end
return 1
end,
}
if tCmds[cmd] then
return tCmds[cmd](curUser, data)
end
end
end
-- Serialize by nErBoS
function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");
assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");
sTab = sTab or "";
sTmp = ""
sTmp = sTmp..sTab..sTableName.." = {\n"
for key, value in tTable do
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end
sTmp = sTmp..",\n"
end
sTmp = sTmp..sTab.."}"
return sTmp
end
function SaveToFile(file , table , tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end
function LoadFromFile(filename)
local f = io.open(filename)
if f then
local r = f:read("*a")
f:flush()
f:close()
local func,err = loadstring(r)
if func then x,err = pcall(func) end
end
end