PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Pieltre on 28 April, 2004, 06:36:56

Title: Plop's oldaccount pruning script
Post by: Pieltre on 28 April, 2004, 06:36:56
Hi,

I got this nice script made by Plop and it works like a marvel, only for one detail.  I want users to also be able to perform the !seen command.  As it is, only OPs and Master can perform it, but there's no reason why regs and vip couldn't use it too.  Is there a way to change the script so that can be done?  Here's the script:

-- auto/manual registered user cleaner if user hasn't been in the hub for x weeks
-- made by plop
-- julian day function made by the guru tezlo
-- code stripped from artificial insanety bot

-- !noclean add/remove  - adds/removes users from/to the list which aren't cleaned
-- !showusers - shows all registered users
-- !seen - shows the last time the user left the hub
-- !shownoclean - shows all names wich are on the noclean list
-- !cleanusers - manualy start the usercleaner

-- a folder named userinfo is needed for this bot 2 work

--------------------------------------------------------------------- config
WEEKS = 12    -- every1 older then x weeks is deleted
Bot = "Bach"
AUTO = 1   -- use 1 for automode, 0 for manual
CleanLevels = {[3]=1,[4]=1,[5]=1} -- levels it needs 2 clean

---------------------------------------------------------------------  the needed tables
UsersTable = {}
Seen = {}
NoClean = {}


--------------------------------------------------------------------- julian day function 2 calcute the time users spend in the hub
function jdate(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 = floor(y/100)
      b = 2 - a + floor(a/4)
   end
   if y <= 0 then c = 0.75 end
   return floor(365.25*y - c) + floor(30.6001*(m+1) + d + 1720994 + b)
end

--------------------------------------------------------------------- loading the last seen database
function LoadLastSeen()
   readfrom("userinfo/lastseen.lst")
   while 1 do
      local line = read()
      if line ==  nil then
         break
      end
      local s,e,name,date = strfind(line, "(.+)$(.+)")
      if name ~= nil then
         Seen[name]=date
      end
   end
   readfrom()
end

--------------------------------------------------------------------- saving last seen date
function SaveSeen()
   writeto("userinfo/lastseen.lst")
   for a,b in Seen do
      Seen[a]=b
      write(a.."$"..b.."\n")
   end
   writeto()
end

--------------------------------------------------------------------- call the garbage man
function Clear()
   collectgarbage()
   flush()
end

--------------------------------------------------------------------- opening the registered users file from ptokax and inserting the users into the table
function OpenRegisterdUsersFile()
   readfrom("../RegisteredUsers.dat")
   UsersTable = nil
   Clear()
   UsersTable = {}
   while 1 do
      local line = read()
      local name, level
      if line == nil then
         readfrom()
         break
      end
      s,e,name,level = strfind(line,"(.+)|.+|(.+)")
      if CleanLevels[tonumber(level)] then
         UsersTable[name] = 1
      end
   end  
end

--------------------------------------------------------------------- extracting the time/date when a user was last seen from the database
function SeenUser(user, data)
   s,e,who = strfind(data, "%b<>%s%S+%s(.+)")
   if who == nil then
      user:SendPM(Bot, "Syntax error, can't read your mind, pls tell me wich user you wanne check|")
   elseif Seen[who] then
      user:SendPM(Bot, who.." was last seen on: "..Seen[who].."|")
   else
      user:SendPM(Bot, who.." is a unknown user|")
   end
end

--------------------------------------------------------------------- shows all the nicks of all registered users
function NewShowUsers(user)
   local lines = {}
   local info = "\r\n\r\n"
   info = info.."  Here are the registered users\r\n"
   info = info.."=====================================\r\n"
   for a,b in UsersTable do
      tinsert(lines, a)
   end
   sort(lines)
   for i=1,getn(lines) do
      info = info.."  "..lines.."\r\n"
   end
   info = info.."=====================================\r\n"
   user:SendPM(Bot, info.." |")
   Clear()
end

--------------------------------------------------------------------- shows all the nicks on the no clean list
function ShowNoClean(user)
   local lines =  {}
   local info = "\r\n\r\n"
   info = info.." Here are the users who aren't cleaned\r\n"
   info = info.."=====================================\r\n"
   for a,b in NoClean do
      tinsert(lines, a)
   end
   sort(lines)
   for i=1,getn(lines) do
      info = info.."  "..lines.."\r\n"
   end
   info = info.."=====================================\r\n"
   user:SendPM(Bot, info.." |")
   Clear()
end

--------------------------------------------------------------------- cleanup old users
function CleanUsers()
   SendToAll(Bot, "The cleaner has been called. Every registered user who hasn't been in the hub for "..WEEKS.." weeks will be deleted. (contact the OP's if your gone be away for a period longer then that)|")
   OpenRegisterdUsersFile()
   local s,e,month,day,year = strfind(date("%x"), "(%d+)%/(%d+)%/(%d+)")
   year = "20"..year
   local juliannow = jdate(tonumber(day), tonumber(month), tonumber(year))
   local oldest = WEEKS*7
   local Count2,Count = 0,0
   for a,b in UsersTable do
      Count = Count+1
      if Seen[a] then
         if NoClean[a]== nil then
            local s,e,monthu,dayu,yearu = strfind(Seen[a], "(%d+)%/(%d+)%/(%d+)")
            yearu = "20"..yearu
            local julianu = jdate(tonumber(dayu), tonumber(monthu), tonumber(yearu))
            if (juliannow - julianu) > oldest then
               Count2 = Count2 +1
               Seen[a] = nil
               DelRegUser(a)
            end
         end
      else
         Seen[a] = date("%x")
      end
   end
   if Count ~= 0 then
      SendToAll(Bot, Count.." users were processed, "..Count2.." of them were deleted.|")
   end
   SaveSeen()
   OpenRegisterdUsersFile()
end

--------------------------------------------------------------------- don't clean this users adding/removing
function NoCleanUser(user, data)
   local s,e,who, addrem = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(%S+)%s*")
   if (who or addrem) == nil then
      user:SendData(Bot, "RTFM ;). it's !noclean |")
   elseif UsersTable[who] then
      if addrem == "add" then
         if NoClean[who] then
            user:SendData(Bot, who.." is allready on the imune list.|")
         else
            NoClean[who] = 1
            user:SendData(Bot, who.." is added to the imune list and won't be cleaned.|")
            SaveNoClean()
         end
      elseif addrem == "remove" then
         if NoClean[who] then
            NoClean[who] = nil
            user:SendData(Bot, who.." is removed from the imune list.|")
            SaveNoClean()
         else
            user:SendData(Bot, who.." was not on the imune list.|")
         end
      else
         user:SendData(Bot, "RTFM ;). it's !noclean |")
      end
   else
      user:SendData(Bot, who.." isn't a registered user.|")
   end
end

--------------------------------------------------------------------- save no clean users 2 file
function SaveNoClean()
   writeto("userinfo/noclean.lst")
   for a,b in NoClean do
      write(a.."\n")
   end
   writeto()
end

--------------------------------------------------------------------- load no clean users from file
function LoadNoClean()
   readfrom("userinfo/noclean.lst")
   while 1 do
      local line = read()
      if line == nil then
         readfrom()
         break
      end
      NoClean[line] = 1
   end
end

--------------------------------------------------------------------- do i need 2 explain this ?????
function DataArrival(user, data)
   if AUTO == 1 then
      if CleanDay ~= date("%x") then -- user cleaning trigger, works as a timer without a timer
         CleanDay = date("%x")
         CleanUsers()
      end
   end
   if( strsub(data, 1, 1) == "<" ) then
      if user.bOperator then
         data=strsub(data,1,strlen(data)-1)
         s,e,cmd = strfind(data,"%b<>%s+(%S+)")
         if cmd == "!noclean" then
            NoCleanUser(user, data)
            return 1
         elseif cmd == "!showusers" then
            NewShowUsers(user)
            return 1
         elseif cmd == "!shownoclean" then
            ShowNoClean(user)
            return 1
         elseif cmd == "!seen" then
            SeenUser(user, data)
            return 1
         elseif cmd =="!cleanusers" then
            CleanUsers()
            return 1
         end
      end
   end
end

--------------------------------------------------------------------- stuff done when a user/vip leaves
function UserDisconnected(user)
   if UsersTable[user.sName] then
      Seen[user.sName]=date("%x")
      SaveSeen()
   end
end

--------------------------------------------------------------------- do the same stuff for op's if needed
function OpDisconnected(user)
   if UsersTable[user.sName] then
      Seen[user.sName]=date("%x")
      SaveSeen()
   end
end

--------------------------------------------------------------------- stuff done on bot startup
function Main()
   OpenRegisterdUsersFile()
   LoadNoClean()
   LoadLastSeen()
   CleanDay = date("%x")
end


Cheers,
Pieltre
Title:
Post by: nErBoS on 28 April, 2004, 13:08:14
Hi,

Done...

-- auto/manual registered user cleaner if user hasn't been in the hub for x weeks
-- made by plop
-- julian day function made by the guru tezlo
-- code stripped from artificial insanety bot

-- !noclean add/remove - adds/removes users from/to the list which aren't cleaned
-- !showusers - shows all registered users
-- !seen - shows the last time the user left the hub
-- !shownoclean - shows all names wich are on the noclean list
-- !cleanusers - manualy start the usercleaner

-- a folder named userinfo is needed for this bot 2 work

--------------------------------------------------------------------- config
WEEKS = 12 -- every1 older then x weeks is deleted
Bot = "Bach"
AUTO = 1 -- use 1 for automode, 0 for manual
CleanLevels = {[3]=1,[4]=1,[5]=1} -- levels it needs 2 clean

--------------------------------------------------------------------- the needed tables
UsersTable = {}
Seen = {}
NoClean = {}


--------------------------------------------------------------------- julian day function 2 calcute the time users spend in the hub
function jdate(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 = floor(y/100)
b = 2 - a + floor(a/4)
end
if y <= 0 then c = 0.75 end
return floor(365.25*y - c) + floor(30.6001*(m+1) + d + 1720994 + b)
end

--------------------------------------------------------------------- loading the last seen database
function LoadLastSeen()
readfrom("userinfo/lastseen.lst")
while 1 do
local line = read()
if line == nil then
break
end
local s,e,name,date = strfind(line, "(.+)$(.+)")
if name ~= nil then
Seen[name]=date
end
end
readfrom()
end

--------------------------------------------------------------------- saving last seen date
function SaveSeen()
writeto("userinfo/lastseen.lst")
for a,b in Seen do
Seen[a]=b
write(a.."$"..b.."\n")
end
writeto()
end

--------------------------------------------------------------------- call the garbage man
function Clear()
collectgarbage()
flush()
end

--------------------------------------------------------------------- opening the registered users file from ptokax and inserting the users into the table
function OpenRegisterdUsersFile()
readfrom("../RegisteredUsers.dat")
UsersTable = nil
Clear()
UsersTable = {}
while 1 do
local line = read()
local name, level
if line == nil then
readfrom()
break
end
s,e,name,level = strfind(line,"(.+)|.+|(.+)")
if CleanLevels[tonumber(level)] then
UsersTable[name] = 1
end
end
end

--------------------------------------------------------------------- extracting the time/date when a user was last seen from the database
function SeenUser(user, data)
s,e,who = strfind(data, "%b<>%s%S+%s(.+)")
if who == nil then
user:SendPM(Bot, "Syntax error, can't read your mind, pls tell me wich user you wanne check|")
elseif Seen[who] then
user:SendPM(Bot, who.." was last seen on: "..Seen[who].."|")
else
user:SendPM(Bot, who.." is a unknown user|")
end
end

--------------------------------------------------------------------- shows all the nicks of all registered users
function NewShowUsers(user)
local lines = {}
local info = "\r\n\r\n"
info = info.." Here are the registered users\r\n"
info = info.."=====================================\r\n"
for a,b in UsersTable do
tinsert(lines, a)
end
sort(lines)
for i=1,getn(lines) do
info = info.." "..lines[i].."\r\n"
end
info = info.."=====================================\r\n"
user:SendPM(Bot, info.." |")
Clear()
end

--------------------------------------------------------------------- shows all the nicks on the no clean list
function ShowNoClean(user)
local lines = {}
local info = "\r\n\r\n"
info = info.." Here are the users who aren't cleaned\r\n"
info = info.."=====================================\r\n"
for a,b in NoClean do
tinsert(lines, a)
end
sort(lines)
for i=1,getn(lines) do
info = info.." "..lines[i].."\r\n"
end
info = info.."=====================================\r\n"
user:SendPM(Bot, info.." |")
Clear()
end

--------------------------------------------------------------------- cleanup old users
function CleanUsers()
SendToAll(Bot, "The cleaner has been called. Every registered user who hasn't been in the hub for "..WEEKS.." weeks will be deleted. (contact the OP's if your gone be away for a period longer then that)|")
OpenRegisterdUsersFile()
local s,e,month,day,year = strfind(date("%x"), "(%d+)%/(%d+)%/(%d+)")
year = "20"..year
local juliannow = jdate(tonumber(day), tonumber(month), tonumber(year))
local oldest = WEEKS*7
local Count2,Count = 0,0
for a,b in UsersTable do
Count = Count+1
if Seen[a] then
if NoClean[a]== nil then
local s,e,monthu,dayu,yearu = strfind(Seen[a], "(%d+)%/(%d+)%/(%d+)")
yearu = "20"..yearu
local julianu = jdate(tonumber(dayu), tonumber(monthu), tonumber(yearu))
if (juliannow - julianu) > oldest then
Count2 = Count2 +1
Seen[a] = nil
DelRegUser(a)
end
end
else
Seen[a] = date("%x")
end
end
if Count ~= 0 then
SendToAll(Bot, Count.." users were processed, "..Count2.." of them were deleted.|")
end
SaveSeen()
OpenRegisterdUsersFile()
end

--------------------------------------------------------------------- don't clean this users adding/removing
function NoCleanUser(user, data)
local s,e,who, addrem = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(%S+)%s*")
if (who or addrem) == nil then
user:SendData(Bot, "RTFM ;). it's !noclean |")
elseif UsersTable[who] then
if addrem == "add" then
if NoClean[who] then
user:SendData(Bot, who.." is allready on the imune list.|")
else
NoClean[who] = 1
user:SendData(Bot, who.." is added to the imune list and won't be cleaned.|")
SaveNoClean()
end
elseif addrem == "remove" then
if NoClean[who] then
NoClean[who] = nil
user:SendData(Bot, who.." is removed from the imune list.|")
SaveNoClean()
else
user:SendData(Bot, who.." was not on the imune list.|")
end
else
user:SendData(Bot, "RTFM ;). it's !noclean |")
end
else
user:SendData(Bot, who.." isn't a registered user.|")
end
end

--------------------------------------------------------------------- save no clean users 2 file
function SaveNoClean()
writeto("userinfo/noclean.lst")
for a,b in NoClean do
write(a.."\n")
end
writeto()
end

--------------------------------------------------------------------- load no clean users from file
function LoadNoClean()
readfrom("userinfo/noclean.lst")
while 1 do
local line = read()
if line == nil then
readfrom()
break
end
NoClean[line] = 1
end
end

--------------------------------------------------------------------- do i need 2 explain this ?????
function DataArrival(user, data)
if AUTO == 1 then
if CleanDay ~= date("%x") then -- user cleaning trigger, works as a timer without a timer
CleanDay = date("%x")
CleanUsers()
end
end
if( strsub(data, 1, 1) == "<" ) then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if cmd == "!noclean" and user.bOperator then
NoCleanUser(user, data)
return 1
elseif cmd == "!showusers" and user.bOperator then
NewShowUsers(user)
return 1
elseif cmd == "!shownoclean" and user.bOperator then
ShowNoClean(user)
return 1
elseif cmd == "!seen" and not user.iProfile == -1 then
SeenUser(user, data)
return 1
elseif cmd =="!cleanusers" and user.bOperator then
CleanUsers()
return 1
end
end
end

--------------------------------------------------------------------- stuff done when a user/vip leaves
function UserDisconnected(user)
if UsersTable[user.sName] then
Seen[user.sName]=date("%x")
SaveSeen()
end
end

--------------------------------------------------------------------- do the same stuff for op's if needed
function OpDisconnected(user)
if UsersTable[user.sName] then
Seen[user.sName]=date("%x")
SaveSeen()
end
end

--------------------------------------------------------------------- stuff done on bot startup
function Main()
OpenRegisterdUsersFile()
LoadNoClean()
LoadLastSeen()
CleanDay = date("%x")
end

Best regards, nErBoS
Title:
Post by: Pieltre on 28 April, 2004, 18:44:46
Hi,

thanks for the prompt reply, but now the !seen command doesn't work at all, neither for me, nor for users...   perhaps a small detail was overlooked?

cheers,
Pieltre
Title:
Post by: Pieltre on 01 May, 2004, 17:59:29
Hi,

Anybody's got an idea on what makes this script not work?

cheers,
Pieltre
Title:
Post by: plop on 02 May, 2004, 02:21:22
this should work.
-- auto/manual registered user cleaner if user hasn't been in the hub for x weeks
-- made by plop
-- julian day function made by the guru tezlo
-- code stripped from artificial insanety bot

-- !noclean add/remove  - adds/removes users from/to the list which aren't cleaned
-- !showusers - shows all registered users
-- !seen - shows the last time the user left the hub
-- !shownoclean - shows all names wich are on the noclean list
-- !cleanusers - manualy start the usercleaner

-- a folder named userinfo is needed for this bot 2 work

--------------------------------------------------------------------- config
WEEKS = 4    -- every1 older then x weeks is deleted
Bot = "The_Cleaner"
AUTO = 1   -- use 1 for automode, 0 for manual
CleanLevels = {[3]=1,[4]=1,[5]=1} -- levels it needs 2 clean

---------------------------------------------------------------------  the needed tables
UsersTable = {}
Seen = {}
NoClean = {}


--------------------------------------------------------------------- julian day function 2 calcute the time users spend in the hub
function jdate(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 = floor(y/100)
b = 2 - a + floor(a/4)
end
if y <= 0 then c = 0.75 end
return floor(365.25*y - c) + floor(30.6001*(m+1) + d + 1720994 + b)
end

--------------------------------------------------------------------- loading the last seen database
function LoadLastSeen()
   readfrom("userinfo/lastseen.lst")
   while 1 do
      local line = read()
      if line ==  nil then
         break
      end
      local s,e,name,date = strfind(line, "(.+)$(.+)")
      if name ~= nil then
         Seen[name]=date
      end
   end
   readfrom()
end

--------------------------------------------------------------------- saving last seen date
function SaveSeen()
   writeto("userinfo/lastseen.lst")
   for a,b in Seen do
      Seen[a]=b
      write(a.."$"..b.."\n")
   end
   writeto()
end

--------------------------------------------------------------------- call the garbage man
function Clear()
   collectgarbage()
   flush()
end

--------------------------------------------------------------------- opening the registered users file from ptokax and inserting the users into the table
function OpenRegisterdUsersFile()
   readfrom("../RegisteredUsers.dat")
   UsersTable = nil
   Clear()
   UsersTable = {}
   while 1 do
      local line = read()
      local name, level
      if line == nil then
         readfrom()
         break
      end
      s,e,name,level = strfind(line,"(.+)|.+|(.+)")
      if CleanLevels[tonumber(level)] then
         UsersTable[name] = 1
      end
   end  
end

--------------------------------------------------------------------- extracting the time/date when a user was last seen from the database
function SeenUser(user, data)
   s,e,who = strfind(data, "%b<>%s%S+%s(.+)")
   if who == nil then
      user:SendPM(Bot, "Syntax error, can't read your mind, pls tell me wich user you wanne check|")
   elseif Seen[who] then
      user:SendPM(Bot, who.." was last seen on: "..Seen[who].."|")
   else
      user:SendPM(Bot, who.." is a unknown user|")
   end
end

--------------------------------------------------------------------- shows all the nicks of all registered users
function NewShowUsers(user)
   local lines = {}
   local info = "\r\n\r\n"
   info = info.."  Here are the registered users\r\n"
   info = info.."=====================================\r\n"
   for a,b in UsersTable do
      tinsert(lines, a)
   end
   sort(lines)
   for i=1,getn(lines) do
      info = info.."  "..lines[i].."\r\n"
   end
   info = info.."=====================================\r\n"
   user:SendPM(Bot, info.." |")
   Clear()
end

--------------------------------------------------------------------- shows all the nicks on the no clean list
function ShowNoClean(user)
   local lines =  {}
   local info = "\r\n\r\n"
   info = info.." Here are the users who aren't cleaned\r\n"
   info = info.."=====================================\r\n"
   for a,b in NoClean do
      tinsert(lines, a)
   end
   sort(lines)
   for i=1,getn(lines) do
      info = info.."  "..lines[i].."\r\n"
   end
   info = info.."=====================================\r\n"
   user:SendPM(Bot, info.." |")
   Clear()
end

--------------------------------------------------------------------- cleanup old users
function CleanUsers()
   SendToAll(Bot, "The cleaner has been called. Every registered user who hasn't been in the hub for "..WEEKS.." weeks will be deleted. (contact the OP's if your gone be away for a period longer then that)|")
   OpenRegisterdUsersFile()
   local s,e,month,day,year = strfind(date("%x"), "(%d+)%/(%d+)%/(%d+)")
   year = "20"..year
   local juliannow = jdate(tonumber(day), tonumber(month), tonumber(year))
   local oldest = WEEKS*7
   local Count2,Count = 0,0
   for a,b in UsersTable do
      Count = Count+1
      if Seen[a] then
         if NoClean[a]== nil then
            local s,e,monthu,dayu,yearu = strfind(Seen[a], "(%d+)%/(%d+)%/(%d+)")
            yearu = "20"..yearu
            local julianu = jdate(tonumber(dayu), tonumber(monthu), tonumber(yearu))
            if (juliannow - julianu) > oldest then
               Count2 = Count2 +1
               Seen[a] = nil
               DelRegUser(a)
            end
         end
      else
         Seen[a] = date("%x")
      end
   end
   if Count ~= 0 then
      SendToAll(Bot, Count.." users were procest, "..Count2.." of them were deleted.|")
   end
   SaveSeen()
   OpenRegisterdUsersFile()
end

--------------------------------------------------------------------- don't clean this users adding/removing
function NoCleanUser(user, data)
   local s,e,who, addrem = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(%S+)%s*")
   if (who or addrem) == nil then
      user:SendData(Bot, "RTFM ;). it's !noclean |")
   elseif UsersTable[who] then
      if addrem == "add" then
         if NoClean[who] then
            user:SendData(Bot, who.." is allready on the imune list.|")
         else
            NoClean[who] = 1
            user:SendData(Bot, who.." is added to the imune list and won't be cleaned.|")
            SaveNoClean()
         end
      elseif addrem == "remove" then
         if NoClean[who] then
            NoClean[who] = nil
            user:SendData(Bot, who.." is removed from the imune list.|")
            SaveNoClean()
         else
            user:SendData(Bot, who.." was not on the imune list.|")
         end
      else
         user:SendData(Bot, "RTFM ;). it's !noclean |")
      end
   else
      user:SendData(Bot, who.." isn't a registered user.|")
   end
end

--------------------------------------------------------------------- save no clean users 2 file
function SaveNoClean()
   writeto("userinfo/noclean.lst")
   for a,b in NoClean do
      write(a.."\n")
   end
   writeto()
end

--------------------------------------------------------------------- load no clean users from file
function LoadNoClean()
   readfrom("userinfo/noclean.lst")
   while 1 do
      local line = read()
      if line == nil then
         readfrom()
         break
      end
      NoClean[line] = 1
   end
end

--------------------------------------------------------------------- do i need 2 explain this ?????
function DataArrival(user, data)
   if AUTO == 1 then
      if CleanDay ~= date("%x") then -- user cleaning trigger, works as a timer without a timer
         CleanDay = date("%x")
         CleanUsers()
      end
   end
   if( strsub(data, 1, 1) == "<" ) then
      if user.bOperator then
         data=strsub(data,1,strlen(data)-1)
         s,e,cmd = strfind(data,"%b<>%s+(%S+)")
         if cmd == "!noclean" then
            NoCleanUser(user, data)
            return 1
         elseif cmd == "!showusers" then
            NewShowUsers(user)
            return 1
         elseif cmd == "!shownoclean" then
            ShowNoClean(user)
            return 1
         elseif cmd == "!seen" then
            SeenUser(user, data)
            return 1
         elseif cmd =="!cleanusers" then
            CleanUsers()
            return 1
         end
      else
         if cmd == "!seen" then
            SeenUser(user, data)
            return 1
      end
   end
end

--------------------------------------------------------------------- stuff done when a user/vip leaves
function UserDisconnected(user)
if UsersTable[user.sName] then
      Seen[user.sName]=date("%x")
      SaveSeen()
   end
end

--------------------------------------------------------------------- do the same stuff for op's if needed
function OpDisconnected(user)
if UsersTable[user.sName] then
      Seen[user.sName]=date("%x")
      SaveSeen()
   end
end

--------------------------------------------------------------------- stuff done on bot startup
function Main()
   OpenRegisterdUsersFile()
   LoadNoClean()
   LoadLastSeen()
   CleanDay = date("%x")
end
plop
Title:
Post by: Pieltre on 04 May, 2004, 19:16:13
Hi,

again, the command doesn't work anymore, neither for OPs,  nor for Users.  Perhaps it's because it can't read the database (something doesn't match...).   Has anyone else tested this script?

cheers,
Pieltre
Title:
Post by: plop on 04 May, 2004, 23:19:20
QuoteOriginally posted by Pieltre
Hi,

again, the command doesn't work anymore, neither for OPs,  nor for Users.  Perhaps it's because it can't read the database (something doesn't match...).   Has anyone else tested this script?

cheers,
Pieltre
there are enough ppl running the script for a long time.
i more expect a conflict with a script your running beside it.
or maby you try on an empty database.

plop
Title:
Post by: Pieltre on 06 May, 2004, 06:25:28
Hi,

thanks for your support and your interest again. I've been using this script for a few months now and it works fine as such. The database is not empty.  My problem is allowing regs to perform the !seen command...   I've tried the latest version of the script in vain.  Nobody can perform the command anymore.  Also, concerning the use of conflicting scripts, I doubt it's an issue. I use Robocop 7 and SAMPLERman's guest script...  and that never prevented the original script from working fine.  

One detail before I give up on this idea to extend the script commands to more status, I got this error message when checking the syntax of the script in Ptokax:

Syntax Error: `end' expected (to close `function' at line 227);
  last token read: `' at line 284 in string "-- auto/manual registered user cleaner if user hasn't been in t..."


I checked at that line and I couldn't find anything clearly wrong...


Cheers,
Pieltre
Title:
Post by: plop on 08 May, 2004, 18:18:12
found it, there was an end missing on dataarrival.
--------------------------------------------------------------------- do i need 2 explain this ?????
-- auto/manual registered user cleaner if user hasn't been in the hub for x weeks
-- made by plop
-- julian day function made by the guru tezlo
-- code stripped from artificial insanety bot

-- !noclean add/remove  - adds/removes users from/to the list which aren't cleaned
-- !showusers - shows all registered users
-- !seen - shows the last time the user left the hub
-- !shownoclean - shows all names wich are on the noclean list
-- !cleanusers - manualy start the usercleaner

-- a folder named userinfo is needed for this bot 2 work

--------------------------------------------------------------------- config
WEEKS = 4    -- every1 older then x weeks is deleted
Bot = "The_Cleaner"
AUTO = 1   -- use 1 for automode, 0 for manual
CleanLevels = {[3]=1,[4]=1,[5]=1} -- levels it needs 2 clean

---------------------------------------------------------------------  the needed tables
UsersTable = {}
Seen = {}
NoClean = {}


--------------------------------------------------------------------- julian day function 2 calcute the time users spend in the hub
function jdate(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 = floor(y/100)
b = 2 - a + floor(a/4)
end
if y <= 0 then c = 0.75 end
return floor(365.25*y - c) + floor(30.6001*(m+1) + d + 1720994 + b)
end

--------------------------------------------------------------------- loading the last seen database
function LoadLastSeen()
   readfrom("userinfo/lastseen.lst")
   while 1 do
      local line = read()
      if line ==  nil then
         break
      end
      local s,e,name,date = strfind(line, "(.+)$(.+)")
      if name ~= nil then
         Seen[name]=date
      end
   end
   readfrom()
end

--------------------------------------------------------------------- saving last seen date
function SaveSeen()
   writeto("userinfo/lastseen.lst")
   for a,b in Seen do
      Seen[a]=b
      write(a.."$"..b.."\n")
   end
   writeto()
end

--------------------------------------------------------------------- call the garbage man
function Clear()
   collectgarbage()
   flush()
end

--------------------------------------------------------------------- opening the registered users file from ptokax and inserting the users into the table
function OpenRegisterdUsersFile()
   readfrom("../RegisteredUsers.dat")
   UsersTable = nil
   Clear()
   UsersTable = {}
   while 1 do
      local line = read()
      local name, level
      if line == nil then
         readfrom()
         break
      end
      s,e,name,level = strfind(line,"(.+)|.+|(.+)")
      if CleanLevels[tonumber(level)] then
         UsersTable[name] = 1
      end
   end  
end

--------------------------------------------------------------------- extracting the time/date when a user was last seen from the database
function SeenUser(user, data)
   s,e,who = strfind(data, "%b<>%s%S+%s(%S+)")
   if who == nil then
      user:SendPM(Bot, "Syntax error, can't read your mind, pls tell me wich user you wanne check|")
   elseif Seen[who] then
      user:SendPM(Bot, who.." was last seen on: "..Seen[who].."|")
   else
      user:SendPM(Bot, who.." is a unknown user|")
   end
end

--------------------------------------------------------------------- shows all the nicks of all registered users
function NewShowUsers(user)
   local lines = {}
   local info = "\r\n\r\n"
   info = info.."  Here are the registered users\r\n"
   info = info.."=====================================\r\n"
   for a,b in UsersTable do
      tinsert(lines, a)
   end
   sort(lines)
   for i=1,getn(lines) do
      info = info.."  "..lines[i].."\r\n"
   end
   info = info.."=====================================\r\n"
   user:SendPM(Bot, info.." |")
   Clear()
end

--------------------------------------------------------------------- shows all the nicks on the no clean list
function ShowNoClean(user)
   local lines =  {}
   local info = "\r\n\r\n"
   info = info.." Here are the users who aren't cleaned\r\n"
   info = info.."=====================================\r\n"
   for a,b in NoClean do
      tinsert(lines, a)
   end
   sort(lines)
   for i=1,getn(lines) do
      info = info.."  "..lines[i].."\r\n"
   end
   info = info.."=====================================\r\n"
   user:SendPM(Bot, info.." |")
   Clear()
end

--------------------------------------------------------------------- cleanup old users
function CleanUsers()
   SendToAll(Bot, "The cleaner has been called. Every registered user who hasn't been in the hub for "..WEEKS.." weeks will be deleted. (contact the OP's if your gone be away for a period longer then that)|")
   OpenRegisterdUsersFile()
   local s,e,month,day,year = strfind(date("%x"), "(%d+)%/(%d+)%/(%d+)")
   year = "20"..year
   local juliannow = jdate(tonumber(day), tonumber(month), tonumber(year))
   local oldest = WEEKS*7
   local Count2,Count = 0,0
   for a,b in UsersTable do
      Count = Count+1
      if Seen[a] then
         if NoClean[a]== nil then
            local s,e,monthu,dayu,yearu = strfind(Seen[a], "(%d+)%/(%d+)%/(%d+)")
            yearu = "20"..yearu
            local julianu = jdate(tonumber(dayu), tonumber(monthu), tonumber(yearu))
            if (juliannow - julianu) > oldest then
               Count2 = Count2 +1
               Seen[a] = nil
               DelRegUser(a)
            end
         end
      else
         Seen[a] = date("%x")
      end
   end
   if Count ~= 0 then
      SendToAll(Bot, Count.." users were procest, "..Count2.." of them were deleted.|")
   end
   SaveSeen()
   OpenRegisterdUsersFile()
end

--------------------------------------------------------------------- don't clean this users adding/removing
function NoCleanUser(user, data)
   local s,e,who, addrem = strfind(data, "%b<>%s+%S+%s+(%S+)%s+(%S+)%s*")
   if (who or addrem) == nil then
      user:SendData(Bot, "RTFM ;). it's !noclean |")
   elseif UsersTable[who] then
      if addrem == "add" then
         if NoClean[who] then
            user:SendData(Bot, who.." is allready on the imune list.|")
         else
            NoClean[who] = 1
            user:SendData(Bot, who.." is added to the imune list and won't be cleaned.|")
            SaveNoClean()
         end
      elseif addrem == "remove" then
         if NoClean[who] then
            NoClean[who] = nil
            user:SendData(Bot, who.." is removed from the imune list.|")
            SaveNoClean()
         else
            user:SendData(Bot, who.." was not on the imune list.|")
         end
      else
         user:SendData(Bot, "RTFM ;). it's !noclean |")
      end
   else
      user:SendData(Bot, who.." isn't a registered user.|")
   end
end

--------------------------------------------------------------------- save no clean users 2 file
function SaveNoClean()
   writeto("userinfo/noclean.lst")
   for a,b in NoClean do
      write(a.."\n")
   end
   writeto()
end

--------------------------------------------------------------------- load no clean users from file
function LoadNoClean()
   readfrom("userinfo/noclean.lst")
   while 1 do
      local line = read()
      if line == nil then
         readfrom()
         break
      end
      NoClean[line] = 1
   end
end

--------------------------------------------------------------------- do i need 2 explain this ?????
function DataArrival(user, data)
   if AUTO == 1 then
      if CleanDay ~= date("%x") then -- user cleaning trigger, works as a timer without a timer
         CleanDay = date("%x")
         CleanUsers()
      end
   end
   if( strsub(data, 1, 1) == "<" ) then
      if user.bOperator then
         data=strsub(data,1,strlen(data)-1)
         s,e,cmd = strfind(data,"%b<>%s+(%S+)")
         if cmd == "!noclean" then
            NoCleanUser(user, data)
            return 1
         elseif cmd == "!showusers" then
            NewShowUsers(user)
            return 1
         elseif cmd == "!shownoclean" then
            ShowNoClean(user)
            return 1
         elseif cmd == "!seen" then
            SeenUser(user, data)
            return 1
         elseif cmd =="!cleanusers" then
            CleanUsers()
            return 1
         end
      else
         if cmd == "!seen" then
            SeenUser(user, data)
            return 1
         end
      end
   end
end

--------------------------------------------------------------------- stuff done when a user/vip leaves
function UserDisconnected(user)
if UsersTable[user.sName] then
      Seen[user.sName]=date("%x")
      SaveSeen()
   end
end

--------------------------------------------------------------------- do the same stuff for op's if needed
function OpDisconnected(user)
if UsersTable[user.sName] then
      Seen[user.sName]=date("%x")
      SaveSeen()
   end
end

--------------------------------------------------------------------- stuff done on bot startup
function Main()
   OpenRegisterdUsersFile()
   LoadNoClean()
   LoadLastSeen()
   CleanDay = date("%x")
end
plop
Title:
Post by: Pieltre on 10 May, 2004, 23:54:10
Hi,

The script now works, but in a completely unexpected way.  I logged in as a REG to test it and here's what it did:

When I typed !seen [username] in the main chat, I got a reply from the Bot listing the username, but no info apart from that.

So for user with the nickname 'Jesus', when I performed
!seen Jesus

I got this message from the bot:

Bot> Jesus

Anything i typed in the main chat, it first wrote it in the Bot instead of the main chat then it gave me this error:

Syntax error, can't read your mind, pls tell me wich user you wanne check



That was quite weird....

Pieltre
Title:
Post by: plop on 11 May, 2004, 00:17:32
copy the code again from the post above, made a small modification.
all the commands only work from the mainchat.
the error msg you gave should only show when you give no username.

plop
Title:
Post by: (=CyberPimp=) on 20 June, 2004, 07:30:50
I would like to see a clean log of all deleted users with the password and date he was last seen and date deleted, to make sure that the script did not make a mistake cos I have had complaints.