PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => Finished Scripts => Topic started by: uffetjur on 15 March, 2008, 14:33:41

Title: Inactive users
Post by: uffetjur on 15 March, 2008, 14:33:41
I'm i a kneed for a script that drops / timeban /kicks users who has been inactice for 24 hours - no posts in PM or main, this for my reghub to keep it cleen from iinactive users!
Title: Re: Inactive users
Post by: Gnuff? on 16 March, 2008, 03:32:18
Quote from: uffetjur on 15 March, 2008, 14:33:41
I'm i a kneed for a script that drops / timeban /kicks users who has been inactice for 24 hours - no posts in PM or main, this for my reghub to keep it cleen from iinactive users!

If that?s what you want, you can be sure your hub will be very empty in short time.
You are in other word forcing users to post in the hub every day, or else they will get kicked, some people have a job too you know  :D
Title: Re: Inactive users
Post by: uffetjur on 17 March, 2008, 01:32:53
as i poinetd out is a hub for speedtest and users are not allowed to download from each other. the only reason for them to enter this hub is to get their share and speed checked!
Title: Re: Inactive users
Post by: Madman on 17 March, 2008, 12:02:21

-- K I U - Kill Inactive User
-- Made by Madman
-- Requested by uffetjur

tConfig = {
Bot = "KIU",
Action = "drop", -- drops / timeban /kick
Msg = "You have been [action] beacuse you havent written a pm or posted in main for [time]",
-- [action] and [time] will be auto replaced with:
-- [action] is the action written in tConfig.Action
-- [time] is the settings written in tConfig.Time table
BanTime = 20, -- Time in Minutes
Time = {
Nr = 10,
Unit = "second",
},
IgnoreCmd = nil,
-- Set to 1 to ignore cmd's as posts in main/pm
-- Set to nil to count cmd's as post in main/pm
}

-- Time Definition
Sec  = 1000
Min  = 60*Sec
Hour = 60*Min
Day  = 24*Hour

function OnStartup()
timID = TmrMan.AddTimer(Min*30) -- Check every 30 min
tUsers = {} -- Store the users...
end

function UserConnected(user)
if tUsers[user.sNick] == nil then
local tTime = os.date("*t")
tUsers[user.sNick] = {}
tUsers[user.sNick]["year"] = tTime.year
tUsers[user.sNick]["month"] = tTime.month
tUsers[user.sNick]["day"] = tTime.day
tUsers[user.sNick]["hour"] = tTime.hour
tUsers[user.sNick]["min"] = tTime.min
tUsers[user.sNick]["sec"] = tTime.sec
end
end

function ChatArrival(user,data)
if tConfig.IgnoreCmd then
local _,_,cmd = string.find(data,"%b<>%s+%p(%S+)")
if cmd then
-- Do Cmds
else
TimeChange(user)
end
else
TimeChange(user)
end
end

ToArrival = ChatArrival

function TimeChange(user)
local tTime = os.date("*t") -- Get time
if not tUsers[user.sNick] then -- If user not in table
tUsers[user.sNick] = {} -- Create table
end
tUsers[user.sNick]["year"] = tTime.year
tUsers[user.sNick]["month"] = tTime.month
tUsers[user.sNick]["day"] = tTime.day
tUsers[user.sNick]["hour"] = tTime.hour
tUsers[user.sNick]["min"] = tTime.min
tUsers[user.sNick]["sec"] = tTime.sec
end

function OnTimer(ID)
if ID == timID then
for i,_ in pairs(tUsers) do -- Loop user table
t = tUsers[i]
t = os.time(t)
local c,d = Convert(t)
if c >= tConfig.Time.Nr and d == tConfig.Time.Unit then -- Check if it's been 24 hours or more
dead = Core.GetUser(i) -- Get online user
if dead then
Msg = string.gsub(tConfig.Msg,"%[action%]",tConfig.Action.."ed") -- Change [action] to the word in tConfig.Action and add ed after it
Msg = string.gsub(Msg,"%[time%]",tConfig.Time.Nr.." "..tConfig.Time.Unit.."s") -- Change [time] to settings in tConfig.Time table
Msg = string.gsub(Msg,"tempbaned", "tempbanned for "..tConfig.BanTime) -- If tempbaned is found correct it to tempbanned and add time
Core.SendToUser(dead,Msg) -- Send msg
if tConfig.Action == "drop" then
Core.Disconnect(dead)
elseif tConfig.Action == "tempban" then
BanMan.TempBan(dead, tConfig.BanTime, Msg, tConfig.Bot,false)
elseif tConfig.Action == "kick" then
Core.Kick(dead, tConfig.Bot, Msg)
else -- if Action is set wrong, inform to opchat
Core.SendToOpChat(tConfig.Bot.. " has an invaild Action configed, it's set to " ..tConfig.Action.. ". It should be drop/kick or tempban, Please ask the owner to change it")
end
end
tUsers[dead.sNick] = nil -- remove user from table
else
-- Just some test code
--Core.SendToAll("<"..tConfig.Bot.."> It's been ["..c.." "..d.."] since " ..i.. "|")
end
end
end
end

Convert = function(time)
-- Made by Mutor
-- EventBot 1.0b LUA 5.11 [Strict][API 2]
-- Modded by Madman
if time then
local s,x,n = "",0,os.time()
local tab = {{31556926,"year"},{2592000,"month"},{604800,"week"},
{86400,"day"},{3600,"hour"},{60,"minute"},{1,"second"}}
if time > 0 then
if time < 2145876659 then
if n > time then
time = n - time
elseif n < time then
time = time - n
end
for i,v in ipairs(tab) do
if time > v[1] then
x = math.floor(time/v[1])
--if x > 1 then v[2] = v[2].."s" end
if x > 1 then v[2] = v[2] end
if x > 0 then
--s = s..x.." "..v[2]..", "
x = x
t = v[2]
time = time-x*v[1]
end
end
end
collectgarbage("collect")
return x,t--s:sub(1,-3)
else
return "Invalid date or time supplied. [must be pre 12/31/2037]"
end
else
return "Invalid date or time supplied. [must be post 01/01/1970]"
end
else
return "Invalid date or time supplied."
end
end


This should do what you want...
Title: Re: Inactive users
Post by: Madman on 17 March, 2008, 12:52:01

-- K I U - Kill Inactive User
-- Made by Madman
-- Requested by uffetjur

-- Version 0.2
-- os.time now directly added to table, less code, suggested by Mutor

tConfig = {
Bot = "KIU",
Action = "drop", -- drops / timeban /kick
Msg = "You have been [action] beacuse you havent written a pm or posted in main for [time]",
-- [action] and [time] will be auto replaced with:
-- [action] is the action written in tConfig.Action
-- [time] is the settings written in tConfig.Time table
BanTime = 20, -- Time in Minutes
Time = {
Nr = 24,
Unit = "hour",
},
IgnoreCmd = nil,
-- Set to 1 to ignore cmd's as posts in main/pm
-- Set to nil to count cmd's as post in main/pm
}

-- Time Definition
Sec  = 1000
Min  = 60*Sec
Hour = 60*Min
Day  = 24*Hour

function OnStartup()
timID = TmrMan.AddTimer(Min*30) -- Check every 30 min
tUsers = {} -- Store the users...
end

function UserConnected(user)
if tUsers[user.sNick] == nil then
tUsers[user.sNick] = {}
tUsers[user.sNick] = os.date("*t")
end
end

function ChatArrival(user,data)
if tConfig.IgnoreCmd then
local _,_,cmd = string.find(data,"%b<>%s+%p(%S+)")
if cmd then
-- Do Cmds
else
TimeChange(user)
end
else
TimeChange(user)
end
end

ToArrival = ChatArrival

function TimeChange(user)
if not tUsers[user.sNick] then -- If user not in table
tUsers[user.sNick] = {} -- Create table
end
tUsers[user.sNick] = os.date("*t") -- Get time
end

function OnTimer(ID)
if ID == timID then
for i,_ in pairs(tUsers) do -- Loop user table
t = tUsers[i]
t = os.time(t)
local c,d = Convert(t)
if c >= tConfig.Time.Nr and d == tConfig.Time.Unit then -- Check if it's been 24 hours or more
dead = Core.GetUser(i) -- Get online user
if dead then
Msg = string.gsub(tConfig.Msg,"%[action%]",tConfig.Action.."ed") -- Change [action] to the word in tConfig.Action and add ed after it
Msg = string.gsub(Msg,"%[time%]",tConfig.Time.Nr.." "..tConfig.Time.Unit.."s") -- Change [time] to settings in tConfig.Time table
Msg = string.gsub(Msg,"tempbaned", "tempbanned for "..tConfig.BanTime) -- If tempbaned is found correct it to tempbanned and add time
Core.SendToUser(dead,Msg) -- Send msg
if tConfig.Action == "drop" then
Core.Disconnect(dead)
elseif tConfig.Action == "tempban" then
BanMan.TempBan(dead, tConfig.BanTime, Msg, tConfig.Bot,false)
elseif tConfig.Action == "kick" then
Core.Kick(dead, tConfig.Bot, Msg)
else -- if Action is set wrong, inform to opchat
Core.SendToOpChat(tConfig.Bot.. " has an invaild Action configed, it's set to " ..tConfig.Action.. ". It should be drop/kick or tempban, Please ask the owner to change it")
end
end
tUsers[dead.sNick] = nil -- remove user from table
else
-- Just some test code
--Core.SendToAll("<"..tConfig.Bot.."> It's been ["..c.." "..d.."] since " ..i.. "|")
end
end
end
end

Convert = function(time)
-- Made by Mutor
-- EventBot 1.0b LUA 5.11 [Strict][API 2]
-- Modded by Madman
if time then
local s,x,n = "",0,os.time()
local tab = {{31556926,"year"},{2592000,"month"},{604800,"week"},
{86400,"day"},{3600,"hour"},{60,"minute"},{1,"second"}}
if time > 0 then
if time < 2145876659 then
if n > time then
time = n - time
elseif n < time then
time = time - n
end
for i,v in ipairs(tab) do
if time > v[1] then
x = math.floor(time/v[1])
--if x > 1 then v[2] = v[2].."s" end
if x > 1 then v[2] = v[2] end
if x > 0 then
--s = s..x.." "..v[2]..", "
x = x
t = v[2]
time = time-x*v[1]
end
end
end
collectgarbage("collect")
return x,t--s:sub(1,-3)
else
return "Invalid date or time supplied. [must be pre 12/31/2037]"
end
else
return "Invalid date or time supplied. [must be post 01/01/1970]"
end
else
return "Invalid date or time supplied."
end
end
Title: Re: Inactive users
Post by: uffetjur on 17 March, 2008, 19:47:45
thanks for a great and fast help to cover my kneed!

- Then Sir, what has chat or pm have to do with it?

Only reason for users to get into that hub is to get in contact with our private hub crew for registrering purposals, and if they dont do that via pm or post in main they have nothing to do their!