PtokaX forum

Archive => Archived 5.0 boards => Finished Scripts => Topic started by: -RICK- on 09 May, 2006, 16:16:33

Title: simpel tagchecker
Post by: -RICK- on 09 May, 2006, 16:16:33

--Tag check (with add and remove)
-- RICK 2006
-- create in scriptsfolder? ? "Tagtable.tbl"



settings = {
["Bot"] = "Tagtablecheck", -- botname
["cmd"] = {["addtag"] = 1, ["remtag"] = 2, ["showtag"] = 3,},
["prefix"] = {["!"] = 1, ["+"] = 1, ["-"] = 1, ["/"] = 1, ["*"] = 1,},
["AllowedProfiles"] = {[-1] = 0, [0] = 1, [1] = 0, [2] = 0, [3] = 1, [4] = 1, [5] = 1,}, -- who can use the commands
}


Tagtable = {}
tcmd={}
TagtableFile = ("Tagtable.tbl")

function Main()
frmHub:RegBot(settings["Bot"])
loadTableFromFile(TagtableFile)
end

function ChatArrival(curUser,data)
local data = string.sub(data,1,string.len(data)-1)
local s,e,prefix,cmd = string.find(data, "%b<>%s*(%S)(%S+)")
if cmd and settings["prefix"][prefix] and settings["cmd"][cmd] then
if settings["cmd"][cmd] ~= nil then
if settings["AllowedProfiles"][curUser.iProfile] == 1 then
if tcmd[settings["cmd"][cmd]] ~= nil then
return tcmd[settings["cmd"][cmd]](curUser, data)
else
curUser:SendData(" *** ??? command incorrect ")
return 1
end
else
curUser:SendData(" *** U dont have acces to this command !")
return 1
end
end
end
end



tcmd[1] = function(user,data)
s,e,arg = string.find(data, "%b<>%s+%S+%s+(.*)")
AddTagtable(user)
return 1
end

function AddTagtable(user)
table.insert(tTagtable, arg)
saveTableToFile(TagtableFile, tTagtable, "tTagtable")
SendToOps(" *** "..arg.." In Tag tabel")
return 1
end

tcmd[2] = function(user,data)
local _,_,arg = string.find(data, "%b<>%s+%S+%s+(.*)")
for i,v in tTagtable do
if v == arg then
table.remove(tTagtable, i)
saveTableToFile(TagtableFile, tTagtable, "tTagtable")
addmsg = (" *** "..arg.." Removed from Tag tabel")
SendToOps(addmsg)
end
end
? ? return 1
end

tcmd[3] = function(user,data)
? ? ? ? tablename = tTagtable
? ? ? ? message1 = ("\t\t\tTag check list ["..table.getn(tTagtable).."] Tag(s)\r\n")
? ? ? ? message2 = ("\tno Tag found in list")
? ? ? ? senddisplay(user)
? ? ? ? return 1
? ? end
? ?
-------------------------------------------------------------
--senddisplay
-------------------------------------------------------------
function senddisplay(user)
? ? ? ? local dsp1
? ? ? ? dsp1 = "\r\n=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n"
? ? ? ? dsp1 = dsp1..""..message1.."\r\n"
? ? ? ? dsp1 = dsp1.."=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n\r\n"
? ? ? ? if table.getn(tablename) ~= 0 then
? ? ? ? ? ? for i = 1,table.getn(tablename) do
? ? ? ? ? ? ? ? dsp1 = dsp1.." "..tablename[i].."\r\n"
? ? ? ? ? ? end
? ? ? ? ? ? else
? ? ? ? ? ? dsp1 = dsp1..""..message2.."\r\n"
? ? ? ? end
? ? ? ? user:SendData(settings["Bot"], dsp1)
? ? ? ? dsp1 = nil
? ? ? ? return 1
? ? end


function checkForTag(user)
for i = 1,table.getn(tTagtable) do
if string.find( user.sTag , tTagtable[i] , 1 , true ) then
? ? ? ? ? ? return 1
end
end
return
end

NewUserConnected = function(user)
? ?if settings["AllowedProfiles"][user.iProfile] == 1 then
? ? ? ? user:SendData("$UserCommand 1 3 Tagtablecheck\\Show Tag$<%[mynick]> !showtag&#124;|")
? ? ? ? user:SendData("$UserCommand 1 3 Tagtablecheck\\Add Tagtable$<%[mynick]> !addtag %[line:Add Tag]&#124;|")
? ? ? ? user:SendData("$UserCommand 1 3 Tagtablecheck\\Rem Tagtable hubs$<%[mynick]> !remtag %[line:Add Tag]&#124;|")
? ? end
end

function MyINFOArrival(user, data)
? ? ? ? if user.sTag == nill then
? ? ? ? ? ? user.sTag = ""
? ? ? ? end
if checkForTag(user)and settings["AllowedProfiles"][user.iProfile] ~= 1 then
? ? ? ? user:SendData(settings["Bot"],"wrong tag")
? ? ? ? user:Disconnect()
? ? end
end

OpConnected=NewUserConnected
------------------------------------------------------------------------------------------------------------------------------------------

Serialize = function(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
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
------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------

saveTableToFile = function(file , table , tablename, tab)
local tempfile = io.open(file, "w")
tempfile:write(Serialize(table, tablename, tab))
tempfile:close()
end
? ? ?
-----------------------------------------------------------
loadTableFromFile = function(file)
dofile(file)
end