Author Topic: Need this sharecheck converted 2 new api  (Read 1841 times)

0 Members and 1 Guest are viewing this topic.

Offline portan

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
Need this sharecheck converted 2 new api
« on: 09 January, 2009, 22:16:49 »
Code: [Select]
--[[

ShareCheck 1.01 - LUA 5.1 by Herman
???????????????????????????????????????
F?r att f? b?ttre kontroll p? vad anv?ndarna delar i Privata Hubbar.

--Inneh?ll
F?rslag vilken user som ?r mest l?mplig att kolla just nu
Info n?r senast en user blev kollad
Statistik och listor
mm.

--kort hj?lp hur den funkar
Man f?r ett f?rslag p? en user genom h?gerklicket och l?gger in den i "tagen"
N?r usern ?r f?rdig kontrollerad l?gger man in personen i "klar"
Man kan l?gga in personer i "kolla" om man inte har tid just nu och den ?r en share som ska kontrolleras

-----------------------------------------
1.01 - changelog
added clean mem function
changed some formating
changed  the way to upgrade the sorted list
fixed a few small bugs
added some more things on show info on user
added new RC "myinfo"
-----------------------------------------

-------------------------------------------------
---Not Added functions. maybe later---
-------------------------------------------------
RC  remove "klara"
RC change OP name
cleanup of database
----------------------------------------------
]]--



tSettings = {

-- Bot Name
sBot_I = "#[Bot]Share",

-- Vem som ska f? felmeddelandena
AdminNick = "[Founder]Rag3Rac3r",

-- Max antal f?r den sorterade listan ?ver users som ska kollas.
--1000 borde funka f?r dom flesta. Men om man har en v?ldigt stor hubb (?ka) eller vill spara p? resurser (minska) antalet users i listan
iMaxList = 1500,

-- Dag f?r start av veckokoll om man har ett krav p? antal fillistor i veckan
-- (as a decimal number with Sunday as 0 (0-6) )
iDay = 4,

-- RightClick Menu
sMenu = "-=ShareCheck=-",

-- directory for files
filedir = "sharecheck\\",

-- User DB
fuserDB = "tSC_user.tbl",

-- OP DB
fopDB = "tSC_op.tbl",

-- kollas DB
fkollasDB = "tSC_kollas.tbl",

-- tagna DB
ftagnaDB = "tSC_tagna.tbl",

-- sorterad lista ?ver folk som ska kollas
flistaDB = "tSC_lista.tbl",

-- log ?ver vilka personer som ?r klara
fklaraLOG = "tSC_klara.log",


--exlude people in the list of users to check =  flistaDB
-- Profiles checked [0 = off; 1 = on]
tProfiles = { [-1] = 0, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1 },

--User that not will be checked --use lowercase
tUser = {["[#hubbfriend][15]Angelina"] = 1},

--Prefix that not will be checked --use lowercase
tPrefix = {
"[#dump]",
"[ma]",
"[founder]",
"[owner]"
}
}

--===============================================================================================================
--     Edit below this on your own risk.                 No support if you do :P
--===============================================================================================================

-- username <> times checked, last check, op checked
tuserDB = {} --  ( iCounter, iTime, sOP )

-- opname <> filelist checked, first time checked, last week
topDB = {} --( iCounter, iTime )

-- username <> op reported, time
tkollasDB = {} --( iTime, sOP )

-- username <> op checked, time
ttagnaDB = {} --( iTime, sOP )

-- username
tlistaDB = {}

-- static numbers
statWeek = 604800
statDay = 86400
statHour = 3600



Main = function()
-- Register BotName if not registered
if tSettings.sBot_I ~= frmHub:GetHubBotName() then frmHub:RegBot(tSettings.sBot_I) end
-- Load DB content
--os.execute("mkdir "..tSettings.filedir)
local r,e = os.rename("web","web")
if e then
if not e:find("Permission denied") then
os.execute("mkdir "..tSettings.filedir)
end
end
if loadfile(tSettings.filedir..tSettings.flistaDB) then dofile(tSettings.filedir..tSettings.flistaDB) end
if loadfile(tSettings.filedir..tSettings.ftagnaDB) then dofile(tSettings.filedir..tSettings.ftagnaDB) end
if loadfile(tSettings.filedir..tSettings.fkollasDB) then dofile(tSettings.filedir..tSettings.fkollasDB) end
if loadfile(tSettings.filedir..tSettings.fuserDB) then dofile(tSettings.filedir..tSettings.fuserDB) end
if loadfile(tSettings.filedir..tSettings.fopDB) then dofile(tSettings.filedir..tSettings.fopDB) end


-- make a sorted list of users who shall be checked if it not exist or is to small
if not next(tlistaDB) then
MakeCheckList()
end
end


NewUserConnected = function(user)

local tRealNick = GetRealNick(user.sName,ttagnaDB)
if tRealNick then
SendPmToNick(ttagnaDB[tRealNick].sOP, tSettings.sBot_I, "ShareCheck: User: "..user.sName.." har loggat in. Finns bland dina tagna")
end

-- Supports UserCommands
if user.bUserCommand then
-- For each entry in table
for i, v in pairs(tCommands) do
-- If member
if v.tLevels[user.iProfile] == 1 then
-- For each type
for n in ipairs(v.tRC) do
-- Send
user:SendData("$UserCommand 1 3 "..tSettings.sMenu.."\\"..v.tRC[n][1]..
"$<%[mynick]> !"..i..v.tRC[n][2].."&#124;")
end
end
end
end
end

OpConnected = NewUserConnected

ChatArrival = function(user, data)
local _,_, to = string.find(data, "^$To:%s(%S+)%s+From:")
local _,_, msg = string.find(data, "%b<>%s(.*)|$")
-- Message sent to Bot or in Main
if (to and to == tSettings.sBot_I) or not to then
-- Parse command
local _,_, cmd = string.find(msg, "^%p(%S+)")
-- Exists
if cmd and tCommands[string.lower(cmd)] then
cmd, user.SendPM = string.lower(cmd), user.SendData
-- PM
if to == tSettings.sBot_I then user.SendPM = user.SendPM end
-- If user has permission
if tCommands[cmd].tLevels[user.iProfile] == 1 then
return tCommands[cmd].fFunction(user, msg), 1
else
return SendPmToNick(user.sName, tSettings.sBot_I, "*** Error: You are not allowed to use this command!"), 1
end
end
end
end

ToArrival = ChatArrival

tCommands = {
deltagen = {
fFunction = function(user, data)
local _,_, nick = string.find(data, "^%S+%s+(%S+)$")

if nick then
local tRealNick = GetRealNick(nick,ttagnaDB)
if tRealNick then
ttagnaDB[tRealNick] = nil
local hFile = io.open(tSettings.filedir..tSettings.ftagnaDB, "w+") Serialize(ttagnaDB, "ttagnaDB", hFile); hFile:close()
SendPmToNick(user.sName,tSettings.sBot_I, "Sharecheck: "..nick.." ?r borttagen fr?n tagen listan")
else
SendPmToNick(user.sName, tSettings.sBot_I, "*** Error: "..nick.." finns inte i tagen listan")
end
else
SendPmToNick(user.sName, tSettings.sBot_I, "*** Syntax Error: L?gg till nicknamn")
end

end,
tLevels = {
[-1] = 0, [0] = 1, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 1,
},
tRC = { { "+ Owner\\Tabort user fr?n tagna", " %[line:Nick]" } }
},
delkollas = {
fFunction = function(user, data)
-- Return
local _,_, nick = string.find(data, "^%S+%s+(%S+)$")
if nick then
local tRealNick = GetRealNick(nick,tkollasDB)
if tRealNick then
tkollasDB[tRealNick] = nil
local hFile = io.open(tSettings.filedir..tSettings.fkollasDB, "w+") Serialize(tkollasDB, "tkollasDB", hFile); hFile:close()
SendPmToNick(user.sName,tSettings.sBot_I, "Sharecheck: "..nick.." ?r borttagen fr?n kollas listan")
else
SendPmToNick(user.sName, tSettings.sBot_I, "*** Error: "..nick.." finns inte i kollas listan")
end
else
SendPmToNick(user.sName, tSettings.sBot_I, "*** Syntax Error: L?gg till nickname")
end

end,
tLevels = {
[-1] = 0, [0] = 1, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 1,
},
tRC = { { "+ Owner\\Tabort user fr?n kollas", " %[line:Nick]" } }
},
forslaguser = {
fFunction = function(user, data)
--loopar igenom kollas f?rst och ser om n?gon ?r online
if next(tkollasDB) then
for i, v in pairs(tkollasDB) do
if GetItemByName(i) then
SendPmToNick(user.sName,tSettings.sBot_I, "ShareCheck: Den mest l?mpliga usern att kolla nu ?r   -->  "..i)
SendPmToNick(user.sName,tSettings.sBot_I, "ShareCheck: kom ih?g att l?gga in den i tagna f?re du b?rjar")
return 1
end
end
end
--om ingen tr?ff i kollas loopas den andra listan igenom och tar f?rsta personen som ?r online
if next(tlistaDB) then
for i = 1, table.maxn(tlistaDB), 1 do
if GetItemByName(tlistaDB[i]) then
SendPmToNick(user.sName,tSettings.sBot_I, "ShareCheck: Den mest l?mpliga usern att kolla nu ?r   -->  "..tlistaDB[i])
SendPmToNick(user.sName,tSettings.sBot_I, "ShareCheck: kom ih?g att l?gga in den i tagen f?re du b?rjar")
return 1
end
end
end
SendPmToNick(user.sName,tSettings.sBot_I, "ShareCheck: Har ingen att rekommendera just nu men ska updatera databasen s? f?rs?k igen om ett tag.")
MakeCheckList()

end,
tLevels = {
[-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 1,
},
tRC = { { "Ge b?sta f?rslaget p? user att kolla", "" } }
},
klarlist = {
fFunction = function(user)
local f = io.open(tSettings.filedir..tSettings.fklaraLOG,"r") --if f then f:close()
if f then
local msg = "made by Herman\r\n"..string.rep("=", 40).."\r\n\tUsers som "..user.sName.." gjort klart\r\n"..string.rep("-", 80).."\r\n"
msg = msg.."Kollade n?r\tOP som addade \tUser\r\n"..string.rep("-", 80).."\r\n"

for line in f:lines() do
local _,_, iTime,sUser,sOp = string.find(line, "(%S+%s%S+)%s(%S+)%s(%S+)")
if string.lower(sOp) == string.lower(user.sName) then
msg = msg..iTime.."\t"..sOp.."  \t"..sUser.."\r\n"
end
end

msg = msg..string.rep("-", 80)
-- Send
SendPmToNick(user.sName, tSettings.sBot_I, msg.."\r\n")

f:close()
else
SendPmToNick(user.sName, tSettings.sBot_I, "*** Error: Det finns ingen klar logfil")
end
end,
tLevels = {
[-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 1,
},
tRC = { { "+ Lista\\Users jag har gjort klart", " %[nick]" } }
},
klarlistowner = {
fFunction = function(user, data)
local _,_, nick = string.find(data, "^%S+%s+(%S+)$")
if nick then
local f = io.open(tSettings.filedir..tSettings.fklaraLOG,"r")
if f then
local msg = "made by Herman\r\n"..string.rep("=", 50).."\r\n\t\tUsers som ?r klara\r\n"..string.rep("-", 100).."\r\n"
msg = msg.."Kollade n?r\tOP som addade\t\tUser\r\n"..string.rep("-", 100).."\r\n"

if nick == "alla" then
for line in f:lines() do
local _,_, iTime,sUser,sOp = string.find(line, "(%S+%s%S+)%s(%S+)%s(%S+)")
msg = msg..iTime.."\t"..sOp.."  \t"..sUser.."\r\n"
end
else
for line in f:lines() do
local _,_, iTime,sUser,sOp = string.find(line, "(%S+%s%S+)%s(%S+)%s(%S+)")
if string.lower(sOp) == string.lower(nick) then
msg = msg..iTime.."\t"..sOp.."  \t"..sUser.."\r\n"
end
end
end
msg = msg..string.rep("-", 100)
-- Send
SendPmToNick(user.sName, tSettings.sBot_I, msg.."\r\n")

f:close()
else
SendPmToNick(user.sName, tSettings.sBot_I, "*** Error: Finns ingen klar logfil")
end
end
end,
tLevels = {
[-1] = 0, [0] = 1, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 1,
},
tRC = { { "+ Owner\\Visa users en op gjort klart", " %[line:OpNick]" }, { "+ Owner\\Visa alla klara users", " alla" } }
},
tagnalist = {
fFunction = function(user, data)
-- Table isn't empty
if next(ttagnaDB) then
local _,_, tVar = string.find(data, "^%S+%s+(%S+)$")

local msg = "made by Herman\r\n"..string.rep("=", 40).."\r\n\tUser i tagna listan:\r\n"..string.rep("-", 80).."\r\n"
msg = msg.."Addade n?r\tUser\t\tOP som addade\r\n"..string.rep("-", 80).."\r\n"
local tCopy ={}
-- Loop through hubbers

for i, v in pairs(ttagnaDB) do
-- Insert stats to temp table
if tVar == "jag" and string.lower(v.sOP)==string.lower(user.sName) then
table.insert(tCopy, { sUser = i, iTime = v.iTime, sOP =v.sOP } )
elseif tVar == "alla" then
table.insert(tCopy, { sUser = i, iTime = v.iTime, sOP =v.sOP } )
end
end
-- Sort by total time
table.sort(tCopy, function(a, b) return (a.iTime < b.iTime) end)
-- Loop through temp table

for i, v in pairs(tCopy) do
msg = msg..os.date("%Y-%m-%d %H:%M",v.iTime).."\t"..v.sUser.."\t"..v.sOP.."\r\n"
end

msg = msg..string.rep("-", 80)
-- Send
SendPmToNick(user.sName, tSettings.sBot_I, msg.."\r\n")
else
SendPmToNick(user.sName, tSettings.sBot_I, "*** Error: tagen listan ?r tom")
end
end,
tLevels = {
[-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 1,
},
tRC = { { "+ Lista\\Alla users som ?r tagna", " alla" }, { "+ Lista\\Mina egna users som ?r tagna", " jag" } }
},
kollaslist = {
fFunction = function(user)
-- Table isn't empty
if next(tkollasDB) then

local msg = "made by Herman\r\n"..string.rep("=", 40).."\r\n\tUser i kollas listan:\r\n"..string.rep("-", 80).."\r\n"
msg = msg.."Addade n?r\tUser\t\tOP som addade\r\n"..string.rep("-", 80).."\r\n"
local tCopy ={}
-- Loop through hubbers

for i, v in pairs(tkollasDB) do
-- Insert stats to temp table
table.insert(tCopy, { sUser = i, iTime = v.iTime, sOP =v.sOP } )
end
-- Sort by total time
table.sort(tCopy, function(a, b) return (a.iTime < b.iTime) end)
-- Loop through temp table

for i, v in pairs(tCopy) do
msg = msg..os.date("%Y-%m-%d %H:%M",v.iTime).."\t"..v.sUser.."\t"..v.sOP.."\r\n"
end

msg = msg..string.rep("-", 80)
-- Send
SendPmToNick(user.sName, tSettings.sBot_I, msg.."\r\n")
else
SendPmToNick(user.sName, tSettings.sBot_I, "*** Error: kollas listan ?r tom")
end
end,
tLevels = {
[-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 1,
},
tRC = { { "+ Lista\\Users som ska kollas", "" } }
},
sctoplista = {
fFunction = function(user)
if next(topDB) then

local msg = "made by Herman\r\n"..string.rep("=", 40).."\r\n  Top-FilListKollare:\r\n"..string.rep("-", 80).."\r\n"
msg = msg.."Antal\tOp\r\n"..string.rep("-", 80).."\r\n"
local tCopy ={}
-- Loop through hubbers
for i, v in pairs(topDB) do
-- Insert stats to temp table
table.insert(tCopy, { sOp = i, iAntal = v.iCounter } )
end
-- Sort by total time
table.sort(tCopy, function(a, b) return (a.iAntal > b.iAntal) end)
-- Loop through temp table
for i, v in pairs(tCopy) do
msg = msg.."  "..v.iAntal.."\t"..v.sOp.."\r\n"
end

msg = msg..string.rep("-", 80)
-- Send
SendPmToNick(user.sName, tSettings.sBot_I, msg.."\r\n")
else
SendPmToNick(user.sName, tSettings.sBot_I, "*** Error: Finns ingen i OPstats listan")
end
end,
tLevels = {
[-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 1,
},
tRC = { { "+ Lista\\Totalt antal kollade", "" }}
},
sctoplistagenomsnitt = {
fFunction = function(user)
-- Table isn't empty
if next(topDB) then

local msg = "made by Herman\r\n"..string.rep("=", 40).."\r\n Genomsnitt per vecka:\r\n"..string.rep("-", 80).."\r\n"
msg = msg.."Snitt\tOp\r\n"..string.rep("-", 80).."\r\n"
local tCopy ={}

--iCounter, iTime )
local iNow = os.time(os.date("*t"))
local iDays, iAntal
-- Loop through hubbers
for i, v in pairs(topDB) do

iDays = (iNow - v.iTime)/statDay
iAntal =string.format("%.2f", ((v.iCounter/iDays)*7))


--iWeeks = math.ceil((iNow - v.iTime)/statWeek)
--iAntal =string.format("<%.2f>", (v.iCounter/iWeeks))

--local _,_,iAntal = string.find((v.iCounter/iWeeks),"(%d+%.?%d?)")




-- Insert stats to temp table
table.insert(tCopy, { sOp = i, iSnitt = tonumber(iAntal) } )
end
-- Sort by total time
table.sort(tCopy, function(a, b) return (a.iSnitt > b.iSnitt) end)
-- Loop through temp table

for i, v in pairs(tCopy) do
msg = msg.."  "..v.iSnitt.."\t"..v.sOp.."\r\n"
end

msg = msg..string.rep("-", 80)
-- Send
SendPmToNick(user.sName, tSettings.sBot_I, msg.."\r\n")
else
SendPmToNick(user.sName, tSettings.sBot_I, "*** Error: Finns ingen i OPstats listan")
end
end,
tLevels = {
[-1] = 0, [0] = 1, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 1,
},
tRC = { { "+ Owner\\Lista ?ver genomsnitt kollade", "" }}
},
veckolista = {
fFunction = function(user, data)
local _,_, tNumber = string.find(data, "^%S+%s+(%d+)$")
local _,_, tStartW,tStopW = string.find(data, "^%S+%s+(%d+)%-(%d+)$")
if tNumber or tStartW then


-- check what weeks user want to see
local iStartWeek,iStopWeek

if tStartW then
iStartWeek = tStartW
iStopWeek = tStopW
tNumber = tStartW.."-"..tStopW
else
iStartWeek = tNumber
iStopWeek = tNumber
end

local tVLista = VeckoLista(iStartWeek,iStopWeek,nil)

-- Skriver ut listan
local msg = "made by Herman\r\n"..string.rep("=", 30).."\r\n Visar info om veckan/veckorna: "..tNumber.."\r\n"..string.rep("=", 30).."\r\n"
for i, v in pairs(tVLista) do
msg = msg.." "..i.." har tagit "..v.iCounter.." users\r\n\r\n"..v.iUsers.."\r\n"..string.rep("-", 60).."\r\n"
end

SendPmToNick(user.sName, tSettings.sBot_I, msg.."\r\n")
tVLista ={}

end
end,
tLevels = {
[-1] = 0, [0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 1,
},
tRC = {{ "+ Owner\\Visa hur m?nga som ?r gjorda - Veckovis", " %[line:En vecka, 0 = p?g?ende, 1=f?rra -- Flera veckor ex 1-4]" } }
},

scvisauser = {
fFunction = function(user, data)
-- Return
local _,_, nick = string.find(data, "^%S+%s+(%S+)$")

if nick then

local msg = "made by Herman\r\n"..string.rep("-", 60).."\r\n         UserInfo for "..nick..":\r\n"..string.rep("-", 60).."\r\n"
--msg = msg.."Username:      \t"..nick.."\r\n"


local tRealNick = GetRealNick(nick,tuserDB)
if tRealNick then
msg = msg.."Last Check:    \t"..os.date("%Y-%m-%d %H:%M",tuserDB[tRealNick].iTime).."\r\n"
msg = msg.."By Who:        \t"..tuserDB[tRealNick].sOP.."\r\n"
msg = msg.."Times checked: \t"..tuserDB[tRealNick].iCounter.."\r\n"
else
msg = msg.."Last Check:    \tNever\r\n"
end

local tRealNick1 = GetRealNick(nick,ttagnaDB)
if tRealNick1 then
msg = msg.."In \"Tagen\":      \tYes by "..ttagnaDB[tRealNick1].sOP.."\r\n"
else
msg = msg.."In \"Tagen\":      \tNo\r\n"
end
local tRealNick2 = GetRealNick(nick,tkollasDB)
if tRealNick2 then
msg = msg.."In \"kollas\": \tYes\r\n"
else
msg = msg.."In \"kollas\": \tNo\r\n"
end

msg = msg..string.rep("-", 60)
SendPmToNick(user.sName, tSettings.sBot_I, msg.."\r\n")

end
end,
tLevels = {
[-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 1,
},
tRC = { { "+ Info\\Visa info om en user", " %[line:Fullst?ndigt Nickname]" }, { "+ Info\\Visa info om denna usern", " %[nick]" } }
},
scvisainfo = {
fFunction = function(user)

local msg = "made by Herman\r\n"..string.rep("=", 30).."\r\n  Information om "..user.sName..":\r\n"..string.rep("=", 30).."\r\n"
--msg = msg.."Username:      \t"..nick.."\r\n"


local tRealNick = GetRealNick(user.sName,topDB)
if tRealNick then

--Veckolistor
local tempDay = tonumber(os.date("%w"))
if tSettings.iDay > tempDay then tempDay = tempDay + 7 end
tempDay = tempDay - tSettings.iDay +7
local tVLista = VeckoLista(0,1,user.sName)

--Genomsnitt
local iDays = (os.time(os.date("*t")) - topDB[tRealNick].iTime)/statDay
local iAntal =string.format("%.2f", ((topDB[tRealNick].iCounter/iDays)*7))


-- Tagna
--local iCount = 0
local sTagna ="\r\nTagna users:\r\n"
for i, v in pairs(ttagnaDB) do
if string.lower(v.sOP)==string.lower(user.sName) then
sTagna = sTagna..os.date("%Y-%m-%d %H:%M",v.iTime).."\t"..i.."\r\n"
--iCount = iCount + 1
end
end

msg = msg.."F?rsta listan kollad:      \t"..os.date("%Y-%m-%d",topDB[tRealNick].iTime).."\r\n"
msg = msg.."Antal listor kollade:      \t"..topDB[tRealNick].iCounter.."\r\n"
msg = msg.."Genomsnitt kollade(vecka): \t"..iAntal.."\r\n\r\n"
msg = msg.."Kollade sista "..tempDay.." dagarna: \t"..tVLista[tRealNick].iCounter.." st\r\n"
msg = msg..tVLista[tRealNick].iUsers.."\r\n"
msg = msg..sTagna.."\r\n"

else
msg = msg.."Du finns inte i databasen. Du m?ste l?gga till en klar f?rst\r\n"
end



msg = msg..string.rep("-", 60)
SendPmToNick(user.sName, tSettings.sBot_I, msg.."\r\n")


end,
tLevels = {
[-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 1,
},
tRC = { { "+ Info\\Visa egen info", "" } }
},
sharecheck = {
fFunction = function(user, data)
local _,_, nick,typ = string.find(data, "^%S+%s+(%S+)%s+(%S+)$")

if nick and typ then

if typ == "tagen" then
if GetRealNick(nick,ttagnaDB) then
SendPmToNick(user.sName, tSettings.sBot_I, "*** Error: "..nick.." ?r redan i tagen listan.")
else

local sText = ""
for i, v in pairs(frmHub:GetRegisteredUsers()) do
if string.lower(v.sNick)==string.lower(nick) then
ttagnaDB[v.sNick] ={iTime=os.time(os.date("*t")),sOP=user.sName}
local hFile = io.open(tSettings.filedir..tSettings.ftagnaDB, "w+") Serialize(ttagnaDB, "ttagnaDB", hFile); hFile:close()
sText = "*** Lyckades:"
end
end
if sText == "" then
SendPmToNick(user.sName, tSettings.sBot_I, "*** Failed: "..nick.." ?r ingen Registerad User! Kolla namnet igen")
else
SendPmToNick(user.sName, tSettings.sBot_I, "Sharecheck: La till "..nick.." i tagen listan")

-- Remove the user from sorted check list
if next(tlistaDB) then
for i = 1, table.maxn(tlistaDB), 1 do
if string.lower(tlistaDB[i]) == string.lower(nick)  then
--tlistaDB[i] = nil
table.remove (tlistaDB , i)
local hFile = io.open(tSettings.filedir..tSettings.flistaDB, "w+") Serialize(tlistaDB, "tlistaDB", hFile); hFile:close()
break
end
end
end

-- Remove the user from kollas
local tRealNick = GetRealNick(nick,tkollasDB)
if tRealNick then
tkollasDB[tRealNick] = nil
local hFile = io.open(tSettings.filedir..tSettings.fkollasDB, "w+") Serialize(tkollasDB, "tkollasDB", hFile); hFile:close()
end
end
end
elseif typ == "kollas"  then
if GetRealNick(nick,tkollasDB) then
SendPmToNick(user.sName, tSettings.sBot_I, "*** Error: "..nick.." ?r redan i kollas listan.")
else
local sText = ""
for i, v in pairs(frmHub:GetRegisteredUsers()) do
if string.lower(v.sNick)==string.lower(nick) then
tkollasDB[v.sNick] ={iTime=os.time(os.date("*t")),sOP=user.sName}
local hFile = io.open(tSettings.filedir..tSettings.fkollasDB, "w+") Serialize(tkollasDB, "tkollasDB", hFile); hFile:close()
sText = "*** Lyckades:"
end
end
if sText == "" then
SendPmToNick(user.sName, tSettings.sBot_I, "*** Failed: "..nick.." ?r ingen Registerad User! Kolla namnet igen")
else
SendPmToNick(user.sName, tSettings.sBot_I, "Sharecheck: La till "..nick.." i kollas listan")
end
end
elseif typ == "klar" then

-- check om den usern finns
local iIsReg = 0
for i, v in pairs(frmHub:GetRegisteredUsers()) do
if string.lower(v.sNick)==string.lower(nick) then

-- add to klara logfile
local hFile = io.open(tSettings.filedir..tSettings.fklaraLOG, "a+")
local tTid = os.time(os.date("*t"))

hFile:write(os.date("%Y-%m-%d %H:%M ",tTid)..nick.." "..user.sName.." ".."\r\n")
hFile:close()

-- Remove the user from tagna
local tRealNick = GetRealNick(nick,ttagnaDB)
if ttagnaDB[tRealNick] then
ttagnaDB[tRealNick] = nil
local hFile = io.open(tSettings.filedir..tSettings.ftagnaDB, "w+") Serialize(ttagnaDB, "ttagnaDB", hFile); hFile:close()
end

-- Remove the user from kollas
local tRealNick = GetRealNick(nick,tkollasDB)
if tRealNick then
tkollasDB[tRealNick] = nil
local hFile = io.open(tSettings.filedir..tSettings.fkollasDB, "w+") Serialize(tkollasDB, "tkollasDB", hFile); hFile:close()
end

-- Remove the user from sorted check list
if next(tlistaDB) then
for i = 1, table.maxn(tlistaDB), 1 do
if string.lower(tlistaDB[i]) == string.lower(nick)  then
--tlistaDB[i] = nil
table.remove (tlistaDB , i)
local hFile = io.open(tSettings.filedir..tSettings.flistaDB, "w+") Serialize(tlistaDB, "tlistaDB", hFile); hFile:close()
break
end
end
end

-- add to stat to opDB
local tRealNick = GetRealNick(user.sName,topDB)
if tRealNick then
topDB[tRealNick].iCounter = topDB[tRealNick].iCounter + 1
else
topDB[user.sName] ={iTime=os.time(os.date("*t")),iCounter = 1}
end
local hFile = io.open(tSettings.filedir..tSettings.fopDB, "w+") Serialize(topDB, "topDB", hFile); hFile:close()


-- add to userDB
local tRealNick = GetRealNick(nick,tuserDB)
if tRealNick then
tuserDB[tRealNick].iTime = os.time(os.date("*t"))
tuserDB[tRealNick].sOP = user.sName
tuserDB[tRealNick].iCounter = tuserDB[tRealNick].iCounter + 1
else
tuserDB[nick] ={iTime=os.time(os.date("*t")),sOP=user.sName,iCounter = 1}
end
local hFile = io.open(tSettings.filedir..tSettings.fuserDB, "w+") Serialize(tuserDB, "tuserDB", hFile); hFile:close()

-- send info to all ops in main
SendPmToOps(tSettings.sBot_I, "Sharecheck: "..user.sName.." la till "..nick.." till klara")
--
iIsReg = 1

end
end
-- koll om personen fanns eller inte
if iIsReg == 0 then SendPmToNick(user.sName, tSettings.sBot_I, "*** Failed: "..nick.." ?r ingen Registerad User! Kolla namnet igen") end


else
SendPmToNick(user.sName, tSettings.sBot_I, "*** Syntax Error: Du m?ste v?lja \"tagen\" , \"klar\" or \"kollas\" ")
end
else
SendPmToNick(user.sName, tSettings.sBot_I, "*** Syntax Error: Inget nickname eller typ")
end
--clean Memory
CleanMem()
end,
tLevels = {
[-1] = 0, [0] = 1, [1] = 1, [2] = 0, [3] = 0, [4] = 0, [5] = 1,
},
tRC = { { "L?gg till user", " %[line:Fullst?ndigt Nickname] %[line:typ: tagen, klar, kollas]" }, { "L?gg till den h?r usern", " %[nick] %[line:typ: tagen, klar, kollas]" } }
},

}

MakeCheckList = function()
local iCounter = 0
local tBol
tlistaDB = {}
for i, v in pairs(frmHub:GetRegisteredUsers()) do

--not checked before
if not GetRealNick(v.sNick,tuserDB) then
-- allowed profile
if tSettings.tProfiles[v.iProfile] and tSettings.tProfiles[v.iProfile] == 1 then
--allowed user
if not tSettings.tUser[string.lower(v.sNick)] then
--allowed prefix
tBol = 0
for key, tFix in pairs(tSettings.tPrefix) do
if string.sub(string.lower(v.sNick),1,string.len(tFix)) == string.lower(tFix) then
tBol = 1
end
end
if tBol == 0 then

table.insert(tlistaDB,v.sNick)
iCounter = iCounter + 1

if iCounter >= tSettings.iMaxList then
break
end
end
end
end
end
end


if iCounter < tSettings.iMaxList then
local tCopy = {}
for i, v in pairs(tuserDB) do
table.insert(tCopy, { sUser = i, iTime = v.iTime} )
end
-- Sort by total time
table.sort(tCopy, function(a, b) return (a.iTime < b.iTime) end)
-- Loop through temp table
for i = 1, table.maxn(tCopy), 1 do
-- i exists
if tCopy[i] then
-- Populate
table.insert(tlistaDB,tCopy[i].sUser)
iCounter = iCounter + 1
if iCounter >= tSettings.iMaxList then
break
end
end
end
tCopy = {}
end
--spara listan
local hFile = io.open(tSettings.filedir..tSettings.flistaDB, "w+") Serialize(tlistaDB, "tlistaDB", hFile); hFile:close()
CleanMem()
end


function VeckoLista(startv,stopv,user)
local tTempV = {}
local f = io.open(tSettings.filedir..tSettings.fklaraLOG,"r") --if f then f:close()
if f then
-- calculate time in seconds to the last "check time"
local iNow = os.time(os.date("*t"))
local tempDay = tonumber(os.date("%w",iNow))
if tSettings.iDay > tempDay then tempDay = tempDay + 7 end
tempDay = tempDay - tSettings.iDay
local iDiffSec = tempDay*statDay + os.date("%H",iNow)*statHour + os.date("%M",iNow)*60 + os.date("%S",iNow)
local iCheckStart = iNow - iDiffSec

for line in f:lines() do
local _,_, iY,iM,iD,iMin,iS,sUser,sOp = string.find(line, "(%d+)%-(%d+)%-(%d+)%s(%d+)%:(%d+)%s(%S+)%s(%S+)")

local iTime = os.time({ year = iY, month = iM, day = iD, hour = iH, min = iMin, sec = iS})
local iStop = iCheckStart - (statWeek*stopv)   
local iStart = iCheckStart - (statWeek*startv) + statWeek           

if user and string.lower(user) == string.lower(sOp) or not user then
if tonumber(iTime) < tonumber(iStart) and tonumber(iTime) > tonumber(iStop) then
if tTempV[sOp] then
tTempV[sOp].iCounter=tTempV[sOp].iCounter+1
tTempV[sOp].iUsers=tTempV[sOp].iUsers..sUser.." , "
else
tTempV[sOp]={iCounter=1,iUsers=sUser.." , "}
end
end
end
end
f:close()
end
return tTempV

end

-- Clean the memory
function CleanMem()
collectgarbage()
io.flush()
end

OnError = function(msg)
SendPmToNick("Herman", tSettings.sBot_I ,"<"..tSettings.sBot_I.."> "..msg)
SendPmToNick(tSettings.AdminNick, tSettings.sBot_I ,"<"..tSettings.sBot_I.."> "..msg)
--OnError("----")
end

GetRealNick = function(user,db)
-- For each hubber
for i, v in pairs(db) do
-- Compare
if string.lower(i) == string.lower(user) then
-- Return
return i
end
end
end

Serialize = function(tTable, sTableName, hFile, sTab)
sTab = sTab or "";
hFile:write(sTab..sTableName.." = {\n");
for key, value in pairs(tTable) do
if (type(value) ~= "function") then
local sKey = (type(key) == "string") and string.format("[%q]", key) or string.format("[%d]", key);
if(type(value) == "table") then
Serialize(value, sKey, hFile, sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q", value) or tostring(value);
hFile:write(sTab.."\t"..sKey.." = "..sValue);
end
hFile:write(",\n");
end
end
hFile:write(sTab.."}");
end

And this to

Code: [Select]
Main = function()
frmHub:RegBot("#[Bot]Share",1,"","")
end

OnExit = function()
frmHub:UnregBot("#[Bot]Share")
end

dont need the # infront of [Bot]Share

PtokaX forum

Need this sharecheck converted 2 new api
« on: 09 January, 2009, 22:16:49 »