PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: D-J Valhala on 31 July, 2004, 17:09:40

Title: Standalone Script Needed
Post by: D-J Valhala on 31 July, 2004, 17:09:40
+logop - will save a log file of all commande that OP's/SuperOp's/Master's are used in the lest 12 hours will not show my commands every 12 hourd the log file will be cleard and with +logop i will see the logfile :)
(Only Masters Can See +logop)

10x  :D
Title:
Post by: kepp on 31 July, 2004, 23:18:35
Ok, I put one togheter, But there's no way i can tell wether it works or not as im unable to test it at the moment

strBot = "OP-Logger";

--// The prefix that is being used for the commands
strPrefix = "!";

sec = 1000;
min = 60*sec

function Main()
if dofile("Commands.lst") == nil then
local handle = openfile("Commands.lst","w")
write(handle,"tblCOM = {\r\n}")
closefile(handle)
else
dofile("Commands.lst")
end
frmHub:RegBot(strBot)
SetTimer(10 * min)
StartTimer()
end

function OnTimer()
WriteFile(tblCOM,"tblCOM","Commands.lst")
end

function DataArrival(curUser,strData)
if (strsub(strData,1,1) == "<") then
local s,e,strCMD = strfind(strData,"%b<>%s+(%S+)")
if (( strCMD == "+logop" )) then
if curUser.iProfile == 0 then
local strLST = "";
for i = 1,getn(tblCOM) do
strLST = strLST.."NAME\t"..tblCOM[i][1].."\tCOMMAND\t"..tblCOM[i][2].."\tDATE\t"..tblCOM[i][3].."\r\n"
end
curUser:SendPM(strBot,"\r\n"..strLST);
return 1;
else
curUser:SendData(strBot,"*** Error, You are not allowed to use this command.")
return 1;
end
elseif (( strCMD == "+clearoplog" )) then
if curUser.iProfile == 0 then
tblCOM = nil;
tblCOM = {}
collectgarbage()
flush()
WriteFile(tblCOM,"tblCOM","Commands.lst")
curUser:SendPM(strBot,"OP-Logger was successfully cleared.")
return 1;
else
curUser:SendData(strBot,"*** Error, You are not allowed to use this command.")
return 1;
end
end
if strsub(strCMD,1,1) == strPrefix then
tinsert(tblCOM,1,{curUser.sName,strCMD,date()})
end
elseif (strsub(strData,1,5) == "$Kick") then
tinsert(tblCOM,1,{curUser.sName,"$KICK",date()})
end
end

function WriteFile(table, tablename, file)
local handle = openfile(file, "w")
Serialize(table, tablename, handle)
  closefile(handle)
end

function Serialize(tTable, sTableName, hFile, sTab)
sTab = sTab or "";
write(hFile, sTab..sTableName.." = {\n" );
for key, value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);
if(type(value) == "table") then
Serialize(value, sKey, hFile, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
write(hFile, sTab.."\t"..sKey.." = "..sValue);
end
write(hFile, ",\n");
end
write(hFile, sTab.."}");
end
Title:
Post by: D-J Valhala on 01 August, 2004, 09:46:26
not working m8