PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => Conversion Requests => Topic started by: miago on 21 April, 2008, 12:22:23

Title: Help needed to convert Sharechecker v1.5 by Leun and TTB
Post by: miago on 21 April, 2008, 12:22:23
Hi again.
There's gonna come up some more scripts I need help with since im gonna change to ptokax 0.4.0.0, but there's no panic, just happy if I get help at any point.
I've searched the board for all of these but havent found any that seems to meet these ones.

This one is the "leecherscript" that we rly have had a great use of.
Thx in advance // Miago

--[[
---------------------------------------------------------------------------------------------------

Sharechecker v1.5 by Leun and TTB
02/01/2006 >> last update: 20/03/2007

Little Changlog:
Added: #llist and #leechers and #lclean
Added: commandlist --> #lhelp
Added: #lcleaner
Fixed: Little bugs, thanx to Mutor
Fixed: Juliandate bug
Changed: Update to lua 5.1


!! For available commands/info see command: #lhelp !!
---------------------------------------------------------------------------------------------------
]]--

---------------------------------------------------------------------------------------------------
-- ## SETTINGS ##--
---------------------------------------------------------------------------------------------------
tSettings = {
Bot = "-Hubname-", -- BotName
sPrefix = "#", -- Command prefix
MinCheck = 10, -- xx checks... more then xx checks and xx days, a message will follow
Days = 14, -- After x days, OPs wil get a notif.
Immune = 1000, --Immune share size in gb...  > xx Gb will not be reported
Admin = "Admin", --Admins Name (error messages // testcase)
File = "check.dat", -- Name of the table
cleantime = 50, -- Clean time; after xx days users will be cleaned from table
SendMsgToUser = true, -- If true user wil receive an notification, if nil not
SendHow = 1,

}

-- The users who needs to be checked:
FileProfiles  = { 
[-1] = 0, --Unregistered User 
[0] = 0, --Master 
[1] = 0, --Operator 
[2] = 0, --Vip 
[3] = 1, --Registered User 
[4] = 0, --Moderator 
[5] = 0, --NetFounder 


-- Who gets those messages and can enter commands?
Profiles  = { 
[-1] = 0, --Unregistered User 
[0] = 1, --Master 
[1] = 0, --Operator 
[2] = 0, --Vip 
[3] = 0, --Registered User 
[4] = 1, --Moderator 
[5] = 1, --NetFounder 
}

---------------------------------------------------------------------------------------------------
-- ## Preloading ##
---------------------------------------------------------------------------------------------------
tShareCheck = {}
tShareCheck.gb = 1024^3
tShareCheck.Safe = tSettings.Immune*tShareCheck.gb

---------------------------------------------------------------------------------------------------
-- ## Message ##
---------------------------------------------------------------------------------------------------
-- Message 2 User
tShareCheck.Msg2User = "*** WARNING Please update your share and Share what you download !!! For "..tSettings.Days.." You have been sharing the same stuff!! ***"

tShareCheck.masslevel = function(msg)
for i,v in pairs(frmHub:GetOnlineUsers()) do
if Profiles[v.iProfile] == 1 then
if SendHow == 1 then
v:SendPM(tSettings.Bot,msg)
else
v:SendPM(frmHub:GetOpChatName(),msg)
end
end
end
end

tShareCheck.Message = function(curUser,count,share,days)
-- msg to OPs
tShareCheck.masslevel("(leecher) User: "..curUser.sName.." // Days: "..days.." // Logins: "..count.." //Share: "..(share/tShareCheck.gb).." Gb")
if SendMsgToUser then
-- msg to user
curUser:SendPM(tSettings.Bot,tShareCheck.Msg2User)
end
end



tShareCheck.CleanMessage = function(clean,checked)
tShareCheck.masslevel("I checked "..checked.." user(s), and I cleaned "..clean.." user(s).")
end

---------------------------------------------------------------------------------------------------
-- ## Standard functions ##
---------------------------------------------------------------------------------------------------
Main = function()
if loadfile(tSettings.File) ~= nil then
dofile(tSettings.File)
else
local f = io.open(tSettings.File, "w")
f:write("check = {}")
f:close()
end
frmHub:RegBot(Bot)
julian = tShareCheck.jdate(tonumber(os.date("%d")), tonumber(os.date("%m")), tonumber(os.date("%Y")))
Today = os.date("%d")
SetTimer(1000)
StartTimer()
end


OnTimer = function()
if time1 == nil then
time1 = 1
else
if time1 < 10 then
time1 = time1+1
else
if os.date("%d")~= Today then
tShareCheck.clean()
Today = os.date("%d")
end
time1 = nil;
end
end
end


ChatArrival = function(curUser,data)
data=string.sub(data,1,string.len(data)-1)
s,e,cmd = string.find(data,"%b<>%s+(%S+)")
if Profiles[curUser.iProfile] == 1 then
if cmd and cmd==tSettings.sPrefix.."llist" then
s,e,cmd,who = string.find(data,"%b<>%s+(%S+)%s+(%S+)")
if who then
if check[who] then
if (julian - check[who]["Dag"]) < tSettings.Days then
SendPmToNick(curUser.sName,tSettings.Bot,"User: "..who.." // Loginshare: "..check[who]["Share"]/tShareCheck.gb.." Gb // Logins: "..check[who]["Count"].." // Days: "..(julian - check[who]["Dag"]))
else
SendPmToNick(curUser.sName,tSettings.Bot,"User: "..who.." // Loginshare: "..check[who]["Share"]/tShareCheck.gb.." Gb // Logins: "..check[who]["Count"].." // Days: "..(julian - check[who]["Dag"]).."  *LEECHER*")
end
else
SendPmToNick(curUser.sName,tSettings.Bot,"User "..who.." is not in list!")
end
else
local bla = "\r\n"
local tel = 0
for i,v in pairs(check) do
tel = tel+1
if (julian - check[i]["Dag"]) < tSettings.Days then
bla = bla..tel..". "..i.." // Loginshare: "..(v["Share"]/tShareCheck.gb).." Gb // Logins: "..v["Count"].." // Days: "..(julian - v["Dag"]).." \r\n"
else
bla = bla..tel..". "..i.." // Loginshare: "..(v["Share"]/tShareCheck.gb).." Gb // Logins: "..v["Count"].." // Days: "..(julian - v["Dag"]).."   *LEECHER* \r\n"
end
end
SendPmToNick(curUser.sName,tSettings.Bot,bla)
bla = nil; tel = nil;
end
return 1
elseif cmd and cmd==tSettings.sPrefix.."leechers" then
local bla = "\r\n"
local tel = 0
for i,v in pairs(check) do
tel = tel+1
if (julian - v["Dag"]) >= tSettings.Days then
bla = bla..tel..". "..i.." // Loginshare: "..(v["Share"]/tShareCheck.gb).." Gb // Logins: "..v["Count"].." // Days: "..(julian - v["Dag"]).."   *LEECHER* \r\n"
end
end
if bla == "\r\n" then
SendPmToNick(curUser.sName,tSettings.Bot,"No leechers found!")
else
SendPmToNick(curUser.sName,tSettings.Bot,bla)
end
bla = nil; tel = nil
return 1
elseif cmd and cmd==tSettings.sPrefix.."lclean" then
s,e,cmd,who = string.find(data,"%b<>%s+(%S+)%s+(%S+)")
if who then
if check[who] then
check[who] = nil
tShareCheck.SaveToFile(tSettings.File, check, "check")
SendPmToNick(curUser.sName,tSettings.Bot,"User "..who.." has been erased from the leecherlist!")
else
SendPmToNick(curUser.sName,tSettings.Bot,"User "..who.." is not in leecherlist!")
end
else
SendPmToNick(curUser.sName,tSettings.Bot,"Who do I need to erase from the list?")
end
return 1
elseif cmd and (cmd==tSettings.sPrefix.."lcleaner") then
tShareCheck.clean()
return 1
elseif cmd and (cmd==tSettings.sPrefix.."lhelp") then
local sDisp = "\r\n\r\n\t"
sDisp = sDisp.."<< Commands >>"
sDisp = sDisp.."\r\n\t"..tSettings.sPrefix.."llist <user>\t- Leech userstats"
sDisp = sDisp.."\r\n\t"..tSettings.sPrefix.."leechers\t\t- Show all leechers"
sDisp = sDisp.."\r\n\t"..tSettings.sPrefix.."lclean <user>\t- Clean leecher from list"
sDisp = sDisp.."\r\n\t"..tSettings.sPrefix.."lcleanall\t- Call the cleaner"
sDisp = sDisp.."\r\n\r\n\t<< Config >>"
sDisp = sDisp.."\r\n\tLeecher\t\t- "..tSettings.Days.." day(s)"
sDisp = sDisp.."\r\n\tLeecher\t\t- "..tSettings.MinCheck.." login(s)"
sDisp = sDisp.."\r\n\tImmune\t\t- >"..tShareCheck.Safe/tShareCheck.gb.." Gb"
sDisp = sDisp.."\r\n\tCleantime\t\t- "..tSettings.cleantime.." day(s)"
sDisp = sDisp.."\r\n\tAdmin\t\t- "..tSettings.Admin
sDisp = sDisp.."\r\n\tFile\t\t- "..tSettings.File
curUser:SendData(tSettings.Bot,sDisp)
return 1
end
end
end

ToArrival = ChatArrival


NewUserConnected = function(curUser)
tShareCheck.UserCheck(curUser,data)
if Profiles[curUser.iProfile] == 1 then
tShareCheck.RC(curUser)
end
end

OpConnected = NewUserConnected

OnError = function(ErrorMsg)
if ErrorMsg then
SendPmToNick(tSettings.Admin,Bot,"(error) "..ErrorMsg)
end
end

-------------------------------------------------------------------------------------------------- 
-- ## JulianDate, day-only ##
--------------------------------------------------------------------------------------------------- 
tShareCheck.jdate = function(d, m, y)   
local a, b, c = 0, 0, 0   
if m <= 2 then y = y - 1; m = m + 12; end   
if (y*10000 + m*100 + d) >= 15821015 then   
a = math.floor(y/100); b = 2 - a + math.floor(a/4)   
end   
if y <= 0 then c = 0.75 end   
return math.floor(365.25*y - c) + math.floor(30.6001*(m+1) + d + 1720994 + b)   
end   

---------------------------------------------------------------------------------------------------
-- ## Usercheck ##
---------------------------------------------------------------------------------------------------
tShareCheck.UserCheck = function (curUser,data)
if (curUser.iShareSize < tShareCheck.Safe) and FileProfiles[curUser.iProfile] == 1 then
if check[curUser.sName] == nil then
check[curUser.sName] = {["Share"] = curUser.iShareSize, ["Count"] = 1, ["Dag"] = julian}
else
if (check[curUser.sName]["Share"] == curUser.iShareSize) then
check[curUser.sName]["Count"] = check[curUser.sName]["Count"]+1
if (check[curUser.sName]["Count"] >= tSettings.MinCheck) and (julian >= check[curUser.sName]["Dag"]+tSettings.Days) and (check[curUser.sName]["Share"] ~= 0) then
tShareCheck.Message(curUser, tonumber(check[curUser.sName]["Count"]), tonumber(check[curUser.sName]["Share"]), tonumber(julian-check[curUser.sName]["Dag"]))
end
else
check[curUser.sName]["Share"] = curUser.iShareSize
check[curUser.sName]["Count"] = 1
check[curUser.sName]["Dag"] = julian
end
end
tShareCheck.SaveToFile(tSettings.File, check, "check")
end
end

-------------------------------------------------------------------------------------------------- 
-- ## Cleaner ##
--------------------------------------------------------------------------------------------------- 
tShareCheck.clean = function()
local checked,clean = 0,0
local sTmp,i,v = ""
julian = tShareCheck.jdate(tonumber(os.date("%d")), tonumber(os.date("%m")), tonumber(os.date("%Y")))
for i,v in pairs(check) do
checked = checked +1
if julian - tonumber(v["Dag"]) >= tSettings.cleantime then
check[i] = nil
clean = clean +1
end
end
tShareCheck.SaveToFile(tSettings.File, check, "check")
tShareCheck.CleanMessage(clean,checked)
end

-------------------------------------------------------------------------------------------------- 
-- ## File Handeling ##
--------------------------------------------------------------------------------------------------

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

tShareCheck.SaveToFile = function(file , table , tablename)
local handle = io.open(file,"w")
tShareCheck.Serialize(table,tablename,handle)
    handle:close()
end

-------------------------------------------------------------------------------------------------- 
-- ## RightClicker ##
--------------------------------------------------------------------------------------------------
tShareCheck.RC = function(curUser)
if curUser then
curUser:SendData("$UserCommand 1 3 - Crew -\\- ShareCheck -\\Leech userstats$<%[mynick]> "..tSettings.sPrefix.."llist %[nick]&#124;|")
curUser:SendData("$UserCommand 1 3 - Crew -\\- ShareCheck -\\Show all leechers$<%[mynick]> "..tSettings.sPrefix.."leechers&#124;|")
curUser:SendData("$UserCommand 1 3 - Crew -\\- ShareCheck -\\Clean leecher from list$<%[mynick]> "..tSettings.sPrefix.."lclean %[nick]&#124;|")
curUser:SendData("$UserCommand 1 3 - Crew -\\- ShareCheck -\\Call the cleaner$<%[mynick]> "..tSettings.sPrefix.."lcleaner&#124;|")
curUser:SendData("$UserCommand 1 3 - Crew -\\- ShareCheck -\\ShareCheck help$<%[mynick]> "..tSettings.sPrefix.."lhelp&#124;|")
curUser:SendData("ShareCheck-[v1.5]", "Rightclick menu for ShareCheck is available...")
end
end
Title: Re: Help needed to convert Sharechecker v1.5 by Leun and TTB
Post by: miago on 21 May, 2008, 16:59:03
Hiya.
Just wondering if there's a possibility to add a request also to this conversion.
Would be great if there was a function to (with option able/disable) send a warning to user who has leeched when time or logins have been met in settings.
And even better if this warn somehow was integrated with ptokax, so after 3 warnings (or whatever settings are in ptokax, robo or other multiscript) the user gets kicked.

Thx in advance
//Miago

PS. If this script is of no interest to be converted by You scriptguys or if maybe it'll be done in the future, plz let me know :) We so wanna change to newer ptokax.
Title: Re: Help needed to convert Sharechecker v1.5 by Leun and TTB
Post by: 2Ceedz on 25 May, 2008, 15:17:34
hate to *bump* a post, but i would like to see this script converted, also, please. 

Thanks In Advance!
Title: Re: Help needed to convert Sharechecker v1.5 by Leun and TTB
Post by: TTB on 29 May, 2008, 15:16:37
I won't update it at short notice, because I've never run/created a script in the newer lua version. Maybe someone else wants to give this script a new light...

Edit: You can try it on your own... make a start :-)
Title: Re: Help needed to convert Sharechecker v1.5 by Leun and TTB
Post by: miago on 25 June, 2008, 14:40:48
Hi.
Decided to try to convert manually with help of other scripts so I have started a little bit.
When starting the script now in ptokax no error appears.
When user connects to the hub I get this errmsg in ptokax: sharechecker1.5_fixed.lua:278: attempt to compare nil with number
I dont know what to do  ??? ??? :-[

Second line in the codesquare down below is line 278.

--Immune share size in gb...  > xx Gb will not be reported   
iImmune    = 1000,

tShareCheck.Safe is a preload:
tShareCheck = {}
tShareCheck.gb = 1024^3
tShareCheck.Safe = tSettings.iImmune*tShareCheck.gb

and tFileProfiles is:
-- The users who needs to be checked:
tFileProfiles  = { 
[-1] = 0, --Unregistered User 
Title: Re: Help needed to convert Sharechecker v1.5 by Leun and TTB
Post by: Cêñoßy†ê on 25 June, 2008, 16:28:04
try this one  ;)
not tested tho


--[[
---------------------------------------------------------------------------------------------------

Sharechecker v1.5 by Leun and TTB
02/01/2006 >> last update: 25/06/2008

Little Changlog:
Added: #llist and #leechers and #lclean
Added: commandlist --> #lhelp
Added: #lcleaner
Fixed: Little bugs, thanx to Mutor
Fixed: Juliandate bug
Changed: Update to lua 5.1
Changed Update to API 2 (C??o?y??)
Added Check if tSettings.Admin is online when reporting error (C??o?y??)


!! For available commands/info see command: #lhelp !!
---------------------------------------------------------------------------------------------------
]]--

---------------------------------------------------------------------------------------------------
-- ## SETTINGS ##--
---------------------------------------------------------------------------------------------------
tSettings = {
Bot = "-Hubname-", -- BotName
sPrefix = "#", -- Command prefix
MinCheck = 10, -- xx checks... more then xx checks and xx days, a message will follow
Days = 14, -- After x days, OPs wil get a notif.
Immune = 1000, --Immune share size in gb...  > xx Gb will not be reported
Admin = "Admin", --Admins Name (error messages // testcase)
File = Core.GetPtokaXPath().."scripts/check.dat", -- Name of the table
cleantime = 50, -- Clean time; after xx days users will be cleaned from table
SendMsgToUser = true, -- If true user wil receive an notification, if nil not
SendHow = 1,

}

-- The users who needs to be checked:
FileProfiles  = { 
[-1] = 0, --Unregistered User 
[0] = 0, --Master 
[1] = 0, --Operator 
[2] = 0, --Vip 
[3] = 1, --Registered User 
[4] = 0, --Moderator 
[5] = 0, --NetFounder 


-- Who gets those messages and can enter commands?
Profiles  = { 
[-1] = 0, --Unregistered User 
[0] = 1, --Master 
[1] = 0, --Operator 
[2] = 0, --Vip 
[3] = 0, --Registered User 
[4] = 1, --Moderator 
[5] = 1, --NetFounder 
}
---------------------------------------------------------------------------------------------------
-- ## Preloading ##
---------------------------------------------------------------------------------------------------
check = {}
tShareCheck = {}
tShareCheck.gb = 1024^3
tShareCheck.Safe = tSettings.Immune*tShareCheck.gb
---------------------------------------------------------------------------------------------------
-- ## Message ##
---------------------------------------------------------------------------------------------------
-- Message 2 User
tShareCheck.Msg2User = "*** WARNING Please update your share and Share what you download !!! For "..tSettings.Days.." You have been sharing the same stuff!! ***"

tShareCheck.masslevel = function(msg)
for i,v in pairs(Core.GetOnlineUsers()) do
if Profiles[v.iProfile] == 1 then
if SendHow == 1 then
Core.SendPmToNick(v.sNick,tSettings.Bot,msg)
else
Core.SendPmToNick(v.sNick,SetMan.GetString(24),msg)
end
end
end
end

tShareCheck.Message = function(curUser,count,share,days)
-- msg to OPs
tShareCheck.masslevel("(leecher) User: "..curUser.sNick.." // Days: "..days.." // Logins: "..count.." //Share: "..(share/tShareCheck.gb).." Gb")
if SendMsgToUser then
-- msg to user
Core.SendPmToNick(curUser.sNick,tSettings.Bot,tShareCheck.Msg2User)
end
end



tShareCheck.CleanMessage = function(clean,checked)
tShareCheck.masslevel("I checked "..checked.." user(s), and I cleaned "..clean.." user(s).")
end

---------------------------------------------------------------------------------------------------
-- ## Standard functions ##
---------------------------------------------------------------------------------------------------
OnStartup = function()
if loadfile(tSettings.File) ~= nil then
dofile(tSettings.File)
else
local f = io.open(tSettings.File, "w+")
f:write("check = {}")
f:close()
end
Core.RegBot(tSettings.Bot,"","",true)
julian = tShareCheck.jdate(tonumber(os.date("%d")), tonumber(os.date("%m")), tonumber(os.date("%Y")))
Today = os.date("%d")
Tmr = {timer=0}
TmrMan.AddTimer(1000,"timer")
end

OnExit = function()
TmrMan.RemoveTimer(Tmr.timer)
end


timer = function()
if time1 == nil then
time1 = 1
else
if time1 < 10 then
time1 = time1+1
else
if os.date("%d")~= Today then
tShareCheck.clean()
Today = os.date("%d")
end
time1 = nil;
end
end
end


ChatArrival = function(curUser,data)
data=string.sub(data,1,string.len(data)-1)
_,_,cmd = data:find("%b<>%s+(%S+)")
if Profiles[curUser.iProfile] == 1 then
if cmd and cmd==tSettings.sPrefix.."llist" then
_,_,cmd,who = data:find("%b<>%s+(%S+)%s+(%S+)")
if who then
if check[who] then
if (julian - check[who]["Dag"]) < tSettings.Days then
Core.SendPmToNick(curUser.sNick,tSettings.Bot,"User: "..who.." // Loginshare: "..check[who]["Share"]/tShareCheck.gb.." Gb // Logins: "..check[who]["Count"].." // Days: "..(julian - check[who]["Dag"]))
else
Core.SendPmToNick(curUser.sNick,tSettings.Bot,"User: "..who.." // Loginshare: "..check[who]["Share"]/tShareCheck.gb.." Gb // Logins: "..check[who]["Count"].." // Days: "..(julian - check[who]["Dag"]).."  *LEECHER*")
end
else
Core.SendPmToNick(curUser.sNick,tSettings.Bot,"User "..who.." is not in list!")
end
else
local bla = "\r\n"
local tel = 0
for i,v in pairs(check) do
tel = tel+1
if (julian - check[i]["Dag"]) < tSettings.Days then
bla = bla..tel..". "..i.." // Loginshare: "..(v["Share"]/tShareCheck.gb).." Gb // Logins: "..v["Count"].." // Days: "..(julian - v["Dag"]).." \r\n"
else
bla = bla..tel..". "..i.." // Loginshare: "..(v["Share"]/tShareCheck.gb).." Gb // Logins: "..v["Count"].." // Days: "..(julian - v["Dag"]).."   *LEECHER* \r\n"
end
end
Core.SendPmToNick(curUser.sNick,tSettings.Bot,bla)
bla = nil; tel = nil;
end
return true
elseif cmd and cmd==tSettings.sPrefix.."leechers" then
local bla = "\r\n"
local tel = 0
for i,v in pairs(check) do
tel = tel+1
if (julian - v["Dag"]) >= tSettings.Days then
bla = bla..tel..". "..i.." // Loginshare: "..(v["Share"]/tShareCheck.gb).." Gb // Logins: "..v["Count"].." // Days: "..(julian - v["Dag"]).."   *LEECHER* \r\n"
end
end
if bla == "\r\n" then
Core.SendPmToNick(curUser.sNick,tSettings.Bot,"No leechers found!")
else
Core.SendPmToNick(curUser.sNick,tSettings.Bot,bla)
end
bla = nil; tel = nil
return true
elseif cmd and cmd==tSettings.sPrefix.."lclean" then
s,e,cmd,who = string.find(data,"%b<>%s+(%S+)%s+(%S+)")
if who then
if check[who] then
check[who] = nil
tShareCheck.SaveToFile(tSettings.File, check, "check")
Core.SendPmToNick(curUser.sNick,tSettings.Bot,"User "..who.." has been erased from the leecherlist!")
else
Core.SendPmToNick(curUser.sNick,tSettings.Bot,"User "..who.." is not in leecherlist!")
end
else
Core.SendPmToNick(curUser.sNick,tSettings.Bot,"Who do I need to erase from the list?")
end
return true
elseif cmd and (cmd==tSettings.sPrefix.."lcleaner") then
tShareCheck.clean()
return true
elseif cmd and (cmd==tSettings.sPrefix.."lhelp") then
local sDisp = "\r\n\r\n\t"
sDisp = sDisp.."<< Commands >>"
sDisp = sDisp.."\r\n\t"..tSettings.sPrefix.."llist <user>\t- Leech userstats"
sDisp = sDisp.."\r\n\t"..tSettings.sPrefix.."leechers\t\t- Show all leechers"
sDisp = sDisp.."\r\n\t"..tSettings.sPrefix.."lclean <user>\t- Clean leecher from list"
sDisp = sDisp.."\r\n\t"..tSettings.sPrefix.."lcleanall\t- Call the cleaner"
sDisp = sDisp.."\r\n\r\n\t<< Config >>"
sDisp = sDisp.."\r\n\tLeecher\t\t- "..tSettings.Days.." day(s)"
sDisp = sDisp.."\r\n\tLeecher\t\t- "..tSettings.MinCheck.." login(s)"
sDisp = sDisp.."\r\n\tImmune\t\t- >"..tShareCheck.Safe/tShareCheck.gb.." Gb"
sDisp = sDisp.."\r\n\tCleantime\t\t- "..tSettings.cleantime.." day(s)"
sDisp = sDisp.."\r\n\tAdmin\t\t- "..tSettings.Admin
sDisp = sDisp.."\r\n\tFile\t\t- "..tSettings.File
Core.SendToNick(curUser.sNick,"<"..tSettings.Bot.."> "..sDisp)
return true
end
end
end

ToArrival = ChatArrival


UserConnected = function(curUser)
tShareCheck.UserCheck(curUser,data)
if Profiles[curUser.iProfile] == 1 then
tShareCheck.RC(curUser)
end
end

RegConnected,OpConnected = UserConnected,UserConnected

OnError = function(ErrorMsg)
if ErrorMsg then
if Core.GetUser(tSettings.Admin) then
Core.SendPmToNick(tSettings.Admin,Bot,"(error) "..ErrorMsg)
end
end
end

-------------------------------------------------------------------------------------------------- 
-- ## JulianDate, day-only ##
--------------------------------------------------------------------------------------------------- 
tShareCheck.jdate = function(d, m, y)   
local a, b, c = 0, 0, 0   
if m <= 2 then y = y - 1; m = m + 12; end   
if (y*10000 + m*100 + d) >= 15821015 then   
a = math.floor(y/100); b = 2 - a + math.floor(a/4)   
end   
if y <= 0 then c = 0.75 end   
return math.floor(365.25*y - c) + math.floor(30.6001*(m+1) + d + 1720994 + b)   
end   

---------------------------------------------------------------------------------------------------
-- ## Usercheck ##
---------------------------------------------------------------------------------------------------
tShareCheck.UserCheck = function (curUser,data)
if (Core.GetUserValue(curUser,16) < tShareCheck.Safe) and FileProfiles[curUser.iProfile] == 1 then
if check[curUser.sNick] == nil then
check[curUser.sNick] = {["Share"] = Core.GetUserValue(curUser,16), ["Count"] = 1, ["Dag"] = julian}
else
if (check[curUser.sNick]["Share"] == Core.GetUserValue(curUser,16)) then
check[curUser.sNick]["Count"] = check[curUser.sNick]["Count"]+1
if (check[curUser.sNick]["Count"] >= tSettings.MinCheck) and (julian >= check[curUser.sNick]["Dag"]+tSettings.Days) and (check[curUser.sNick]["Share"] ~= 0) then
tShareCheck.Message(curUser, tonumber(check[curUser.sNick]["Count"]), tonumber(check[curUser.sNick]["Share"]), tonumber(julian-check[curUser.sNick]["Dag"]))
end
else
check[curUser.sNick]["Share"] = Core.GetUserValue(curUser,16)
check[curUser.sNick]["Count"] = 1
check[curUser.sNick]["Dag"] = julian
end
end
tShareCheck.SaveToFile(tSettings.File, check, "check")
end
end

-------------------------------------------------------------------------------------------------- 
-- ## Cleaner ##
--------------------------------------------------------------------------------------------------- 
tShareCheck.clean = function()
local checked,clean = 0,0
local sTmp,i,v = ""
julian = tShareCheck.jdate(tonumber(os.date("%d")), tonumber(os.date("%m")), tonumber(os.date("%Y")))
for i,v in pairs(check) do
checked = checked +1
if julian - tonumber(v["Dag"]) >= tSettings.cleantime then
check[i] = nil
clean = clean +1
end
end
tShareCheck.SaveToFile(tSettings.File, check, "check")
tShareCheck.CleanMessage(clean,checked)
end

-------------------------------------------------------------------------------------------------- 
-- ## File Handeling ##
--------------------------------------------------------------------------------------------------

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

tShareCheck.SaveToFile = function(file , table , tablename)
local handle = io.open(file,"w")
tShareCheck.Serialize(table,tablename,handle)
    handle:close()
end

-------------------------------------------------------------------------------------------------- 
-- ## RightClicker ##
--------------------------------------------------------------------------------------------------
tShareCheck.RC = function(curUser)
if curUser then
Core.SendToUser(curUser,"$UserCommand 1 3 - Crew -\\- ShareCheck -\\Leech userstats$<%[mynick]> "..tSettings.sPrefix.."llist %[nick]&#124;")
Core.SendToUser(curUser,"$UserCommand 1 3 - Crew -\\- ShareCheck -\\Show all leechers$<%[mynick]> "..tSettings.sPrefix.."leechers&#124;")
Core.SendToUser(curUser,"$UserCommand 1 3 - Crew -\\- ShareCheck -\\Clean leecher from list$<%[mynick]> "..tSettings.sPrefix.."lclean %[nick]&#124;")
Core.SendToUser(curUser,"$UserCommand 1 3 - Crew -\\- ShareCheck -\\Call the cleaner$<%[mynick]> "..tSettings.sPrefix.."lcleaner&#124;")
Core.SendToUser(curUser,"$UserCommand 1 3 - Crew -\\- ShareCheck -\\ShareCheck help$<%[mynick]> "..tSettings.sPrefix.."lhelp&#124;")
Core.SendToUser(curUser,"<ShareCheck-[v1.5]> Rightclick menu for ShareCheck is available...")
end
end
Title: Re: Help needed to convert Sharechecker v1.5 by Leun and TTB
Post by: miago on 25 June, 2008, 20:55:42
Hi there.

Thx, been testing a little bit.
Commands works fine under RC and also when U type them manually.

The things that doesnt work is that when a user who enters the hub and is a leecher, doesnt get a pm about his leecherstatus. And at the same time, the opchat doesnt get that statusmessage about the leecher entering the hub. (the opchat name in settings in ptokax is -CrewRoom- )   (no spaces and no $ in the name)

Otherwise it seems to work as we like it =)

Cheers
miago