PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Millsy on 19 February, 2004, 20:09:35

Title: A Few Mods Plz
Post by: Millsy on 19 February, 2004, 20:09:35
--// Millsy's Idear ----------------------------------------------------
-- To run on + command
-- works like this but shows command when run

--Artbot 1.0 made by: [NL]MrBuitenhuizen
--Artbot has most of the scripting lines from > :
-->ShowInfo v1.0 by latinmusic == poweroperator 18/04/2003
--Based on TrickerBot 2 by ?Ptaczek?
--Based on a few lines of DirtyBot made by Dirty Finger)
-->Brutus 0.2. by Troubadour
-->you need to have the directory "art" in your txt directory (so it won't become a mess to search for the files ;) )
--have fun with it

BotName = "Art Bot"
Files = {
["+art"] = "art.txt",


}
function Main()
end
function DataArrival(user, data)
if( strsub(data, 1, 1) == "<" ) then
s,e,msg = strfind(data, "%b<> ([ -z]*)")
for key, value in Files do
if( strfind( strlower(msg), key) ) then
txtToShow, x = gsub(value, "%b[]", user.sName)
SendToAll( data )
Show(user, TheFile)
return 1
end
end
end
end
function Show(user, TheFile)
readfrom(txtToShow, "r")
local message = ""
while 1 do
local line = read()
if line == nil then break
else
message = message..line.."\r\n"
end
end
SendToAll( BotName, message ) -- send bot's message
readfrom()
return 1;
end


--// Millsy's Idear ----------------------------------------------------
-- Send in PM

--Hub Stats V.01 by chill
--Serialisation by RabidWombat

statFile = "hubstats.txt"   -- The Filename
statFolder = ""      -- The Foldername set it to nil if not wanted
Max1 = 1         -- Time between each stats saving
cmd1 = "+hubstats"      -- Shows the Hub Stats

--------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
--   MAIN SCRIPT
--------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------

if statFolder then
   statFile = statFolder.."/"..statFile
end

HubStats = {
   Logins = 0,
   MaxShareAmount = frmHub:GetCurrentShareAmount(),
   MaxUsers = frmHub:GetUsersCount(),
   StatsSince = date("%d/%m/%y"),
}
dofile(statFile)
--------------------------------------------------------
function Main()
   SetTimer(60*1000*Max1)
   StartTimer()
end
function OnExit()
   WriteTable(HubStats,"HubStats",statFile)
end
--------------------------------------------------------
function OnTimer()
   WriteTable(HubStats,"HubStats",statFile)
end
--------------------------------------------------------
function NewUserConnected(curUser)
   if (frmHub:GetCurrentShareAmount() > HubStats.MaxShareAmount) then
      HubStats.MaxShareAmount = frmHub:GetCurrentShareAmount()
   end
   if (frmHub:GetUsersCount() > HubStats.MaxUsers) then
      HubStats.MaxUsers = frmHub:GetUsersCount()
   end
   HubStats.Logins = HubStats.Logins + 1
end
OpConnected = NewUserConnected
--------------------------------------------------------
function DataArrival(curUser,data)
   if strsub(data,1,1) == "<" then
      data = strsub(data,strlen(curUser.sName)+4,strlen(data)-1)
      local _,_,word1 = strfind(data,"^(%S+)")
      if word1 and hubStatFunc[word1] then
         curUser:SendData(hubStatFunc[word1]())
         return 1
      end
   end
end
---------------------------------------------------------------------------------------

--   Hub Stats Functions
---------------------------------------------------------------------------------------
hubStatFunc = {
   [cmd1] = function()
      local msg = "\r\n\t\t\t---  Hub Stats Since "..HubStats.StatsSince.."  ---\r\n\r\n"
      msg = msg.."\tLogins: "..HubStats.Logins.."\r\n"..
      "\tPeak Users: "..HubStats.MaxUsers.."   -   Current Users: "..frmHub:GetUsersCount().."   -   Max Users Allowed: "..frmHub:GetMaxUsers().."\r\n"..
      "\tPeak Share: "..format("%.2f",(HubStats.MaxShareAmount/(1024*1024*1024*1024)))..
      "   -   Current Share: "..format("%.2f",(frmHub:GetCurrentShareAmount()/(1024*1024*1024*1024))).." TB"..
      "   -   Share/User: "..format("%.2f",(frmHub:GetCurrentShareAmount()/(1024*1024*1024)/frmHub:GetUsersCount())).." GB/User\r\n\r\n"..
      GetReggedUsers()
      return(msg)
   end,
}

function GetReggedUsers()
   local tcount,pcount = 0,0
   local msg = ""
   for _,profile in GetProfiles() do
      pcount = pcount + 1
      local ucount = 0
      for _,_ in GetUsersByProfile(profile) do
         ucount = ucount + 1
         tcount = tcount + 1
      end
      msg = msg.."\t    - "..profile..": "..ucount.."\r\n"
   end
   msg = "\tTotal Regged User: "..tcount.." in "..pcount.." Profiles\r\n\r\n"..msg
   return(msg)
end
---------------------------------------------------------------------------------------

--   Write Tables

---------------------------------------------------------------------------------------
function WriteTable(table,tablename,file)
   local handle = openfile(file,"w")
   Serialize(table,tablename,handle)
     closefile(handle)
end
--------------------------------------------
function Serialize(tTable,sTableName,hFile,sTab)
   sTab = sTab or "";
   write(hFile,sTab..sTableName.." = {\n");
   for key,value in tTable do
      local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);
      if(type(value) == "table") then
         Serialize(value,sKey,hFile,sTab.."\t");
      else
         local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
         write(hFile,sTab.."\t"..sKey.." = "..sValue);
      end
      write(hFile,",\n");
   end
   write(hFile,sTab.."}");
end


--// Millsy's Idear ----------------------------------------------------
-- Insted of "+topuptimes" have
-- Top Uptimes 4 ops and masters "+opuptimes"
-- Top Uptimes 4 reg and nonreg users "+useruptimes"

-- Name this bot to what you want
bot="Hub-Security"

--Name the commands to what you like
cmd1 = "+myuptime"
cmd2 = "+topuptimes"
cmd3 = "+hubuptime"

--This number stands for the maximum of displayed users, set it to what U like
Max = 50
--This number is for the timespan between each data saving in minutes.
Max1 = 1
--This number stands for time in minutes, a user must be online till he is saved to the file.
Max2 = 1
---------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------

HTFolder = "../scripts"

File1 = "hub-time.txt"

sec = 1000
min = 60 * sec

var1 = 0
SHT = 0
HubUpTime = HubUpTime or 0
UserHubTime = {}
UserSessionTime = {}

dofile(HTFolder.."/"..File1)

function Main()
   SetTimer(1 * min)
   StartTimer()
   foreach(UserHubTime, function(i,_)
      if GetItemByName(i) then
         UserSessionTime = 0
      end
   end)
   TopOnliners = GetUserMaxTime()
   UpdateTime = "Updated: "..date("%d/%m/%y at %H:%M:%S")
end

function OnTimer()
   SHT = SHT + 1
   foreach(UserSessionTime, function(i,_)
      if GetItemByName(i) then
         UserSessionTime = UserSessionTime + 1
      end
   end)
   var1 = var1 + 1
   if var1 >= Max1 then
      foreach(UserSessionTime, function (a,_)
         UserHubTime[a] = UserHubTime[a] + UserSessionTime[a]
         UserSessionTime[a] = 0
         if not GetItemByName(a) then
            UserSessionTime[a] = nil
         end
      end)
      HubUpTime = HubUpTime + SHT
      WriteFile(UserHubTime, "UserHubTime", File1)
      var1 = 0
      SHT = 0
      TopOnliners = GetUserMaxTime()
      UpdateTime = "Updated: "..date("%d/%m/%y at %H:%M:%S")
   end
end

function OnExit()
   foreach(UserSessionTime, function (a,_)
      UserHubTime[a] = UserHubTime[a] + UserSessionTime[a]
      UserSessionTime[a] = 0
      if not GetItemByName(a) then
         UserSessionTime[a] = nil
      end
   end)
   HubUpTime = HubUpTime + SHT
   WriteFile(UserHubTime, "UserHubTime", File1)
end

function NewUserConnected(curUser)
   if UserHubTime[curUser.sName]==nil then
      UserHubTime[curUser.sName]=0
   end
   UserSessionTime[curUser.sName]=0
end

OpConnected = NewUserConnected

function DataArrival(curUser,data)
   if (strsub(data, 1, 1) == "<") then
      data = strsub(data,1,strlen(data)-1)
      local _,_,cmd = strfind( data, "%b<>%s+(%S+)" )

      if (cmd and strlower(cmd) == strlower(cmd1) and UserHubTime[curUser.sName]) then
         local tmp = UserHubTime[curUser.sName] + UserSessionTime[curUser.sName]
         local months, days, hours, minutes = floor(tmp/43200), floor(mod(tmp/1440, 30)), floor(mod(tmp/60, 24)), floor(mod(tmp/1, 60))
         curUser:SendData(bot, "You have been online : "..months.." months, "..days.." days, "..hours.." hours, "..minutes.." minutes ( "..tmp.." min ). That is "..format("%.2f",tmp/HubUpTime*100).." % of the total HubUpTime.")
         return 1

      elseif (cmd and strlower(cmd) == strlower(cmd2)) then
         local tmp = HubUpTime + SHT
         local months, days, hours, minutes = floor(tmp/43200), floor(mod(tmp/1440, 30)), floor(mod(tmp/60, 24)), floor(mod(tmp/1, 60))
         curUser:SendPM(bot, "The Top "..Max.." Users - "..UpdateTime.." \r\n\r\n"..
         "\tHub's Online Time : "..months.." months, "..days.." days, "..hours.." hours, "..minutes.." minutes ( "..tmp.." min ).\r\n"..
         TopOnliners.."\r\n")
         return 1

      elseif (cmd and strlower(cmd) == strlower(cmd3)) then
         local tmp = HubUpTime + SHT
         local months, days, hours, minutes = floor(tmp/43200), floor(mod(tmp/1440, 30)), floor(mod(tmp/60, 24)), floor(mod(tmp/1, 60))
         curUser:SendData(bot, "The hub has now been online : "..months.." months, "..days.." days, "..hours.." hours, "..minutes.." minutes ( "..tmp.." min ).")
         return 1

      end
   end
end
----------------------------------------------------------------------------------------------------------
function WriteFile(table, tablename, file)
   local handle = openfile(HTFolder.."/"..file, "w")
   write(handle, tablename.." = {\n" )
   for key, value in table do
      if value >= Max2 then
         write(handle, "\t"..format("[%q]",key).." = "..value..",\n")
      end
   end
   write(handle, "}");
   write(handle,"\r\nHubUpTime = "..HubUpTime)
     closefile(handle)
end
----------------------------------------------------------------------------------------------------------
function GetUserMaxTime()
   local TCopy={}
   for i,v in UserHubTime do
      tinsert( TCopy, { tonumber(v),i } )
   end
   sort( TCopy, function(a, b) return (a[1] > b[1]) end)
   local msg ="\r\n"
   for i = 1,Max do
      if TCopy then
         local months, days, hours, minutes = floor(TCopy[1]/43200), floor(mod(TCopy[1]/1440, 30)), floor(mod(TCopy[1]/60, 24)), floor(mod(TCopy[1]/1, 60))
         msg = msg.."\t# "..i.."  -  "..TCopy[2].."\t::\t"..months.." Months, "..days.." Days, "..hours.." Hours, "..minutes.." Min ( "..TCopy[1].." min ).\r\n"
      end
   end
   local TCopy={}
   return msg
end
Title:
Post by: Millsy on 22 February, 2004, 00:36:45
please can some one help
Title:
Post by: Millsy on 25 February, 2004, 00:11:06
Please Can Someone sort this out please

To run on + command
works like this but shows command when run

--Artbot 1.0 made by: [NL]MrBuitenhuizen
--Artbot has most of the scripting lines from > :
-->ShowInfo v1.0 by latinmusic == poweroperator 18/04/2003
--Based on TrickerBot 2 by ?Ptaczek?
--Based on a few lines of DirtyBot made by Dirty Finger)
-->Brutus 0.2. by Troubadour
-->you need to have the directory "art" in your txt directory (so it won't become a mess to search for the files ;) )
--have fun with it

BotName = "Art Bot"
Files = {
["+art"] = "art.txt",


}
function Main()
end
function DataArrival(user, data)
if( strsub(data, 1, 1) == "<" ) then
s,e,msg = strfind(data, "%b<> ([ -z]*)")
for key, value in Files do
if( strfind( strlower(msg), key) ) then
txtToShow, x = gsub(value, "%b[]", user.sName)
SendToAll( data )
Show(user, TheFile)
return 1
end
end
end
end
function Show(user, TheFile)
readfrom(txtToShow, "r")
local message = ""
while 1 do
local line = read()
if line == nil then break
else
message = message..line.."\r\n"
end
end
SendToAll( BotName, message ) -- send bot's message
readfrom()
return 1;
end
Title:
Post by: plop on 07 March, 2004, 23:21:35
place -- before the lines with return 1, then the commands should appear in the chat.

change:
if( strfind( strlower(msg), key) ) then

for
if( strfind( strlower(msg), ("+"..key)) ) then
should have the result that all commands work as +commands.

plop