PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: damo on 27 May, 2005, 00:47:08

Title: share Controler
Post by: damo on 27 May, 2005, 00:47:08
maybe someone can help me with this table conversion please i have changed the script from lua 4 thats if its right

--Requested by jsjen
--Made by nErBoS

Bot = "Share-Controler"

sharertxt = "shares.txt" --Will be created in the script folder
sh = {}

function Main()
   frmHub:RegBot(Bot)
end

function NewUserConnected(user, data)
   local s,e,share = string.find(user.sMyInfoString, "%$%s*(%d+)%$")
   share = string.format("%0.2f", tonumber(share)/(1024*1024*1024))
   CheckShare(user, share)
end

OpConnected = NewUserConnected

function ChatArrival(user, data)
   if (string.sub(data,1,1)=="<") or (string.sub(data,1,5+string.len(Bot))=="$To: "..Bot) then
   data=string.sub(data,1,string.len(data)-1)
   s,e,cmd = string.find(data,"%b<>%s+(%S+)")
      if (cmd=="!sgrw") then
         if (user.bOperator) then
            local s,e,who = string.find(data,"%b<>%s+%S+%s+(%S+)")
            if (who == nil or who == "") then
               user:SendPM(Bot, "Syntax Error, !sgrw , you must write a name.")
            else
               user:SendPM(Bot, CheckUser(who))
            end
         else
            user:SendPM(Bot, "You don?t have permission to use this command.")
         end
         return 1
      end
   end
end

function CheckUser(user)
local tmp = ""
   if (readfrom(sharertxt) == nil) then
      tmp = tmp.."the file hasn't been created yet."
   else
      readfrom(sharertxt)
      while 1 do
      local line = read()
         if (line == nil) then
            tmp = tmp.."The user "..user.." wasn't found in the list, have you write the right name ?"
            break
         else
            local s,e,who,lshare, fshare = string.find(line, "(%S+)%s+%&%s+(%S+)%s+&%s+(%S+)")
            if (who ~= nil and string.lower(who) == string.lower(user) ) then
               if (GetItemByName(user) ~= nil) then
                  tmp = tmp.."The user "..user.." is sharing "..lshare.." GB his last share was "..fshare.." GB."
               else
                  tmp = tmp.."The user "..user.." has shared "..lshare.." GB."
               end
               break
            end
         end
      end
      readfrom()
   end
return tmp
end
      

function CheckShare(user, share)
local tmp = ""
local time = 0
   if (readfrom(sharertxt) == nil) then
      writeto(sharertxt)
      write(user.sName.." & "..share.." & 0\r\n")
      writeto()
   else
      readfrom(sharertxt)
      while 1 do
      local line = read()
         if (line == nil) then
            if (time == 0) then
               tmp = tmp..user.sName.." & "..share.." & 0\r\n"
            end
            break
         else
            local s,e,who,nshare = string.find(line, "(%S+)%s+%&%s+(%S+)%s+&%s+%S+")
            if (who ~= nil and string.lower(who) == string.lower(user.sName)) then
               if (tonumber(nshare) > tonumber(share)) then
                  SendPmToOps(Bot, "The user "..user.sName.." has least share then his last loggin.")
                  SendPmToOps(Bot, "He had "..nshare.." GB and now he has "..share.." GB.")
                  tmp = tmp..user.sName.." & "..share.." & "..nshare.."\r\n"
                  sh[user.sName] = share
                  time = 1
               elseif (tonumber(nshare) < tonumber(share)) then
                  SendPmToOps(Bot, "The user "..user.sName.." has more share then his last loggin.")
                  SendPmToOps(Bot, "He had "..nshare.." GB and now he has "..share.." GB.")
                  tmp = tmp..user.sName.." & "..share.." & "..nshare.."\r\n"
                  sh[user.sName] = share
                  time = 1
               elseif (tonumber(nshare) == tonumber(share)) then
                  tmp = tmp..user.sName.." & "..share.." & "..nshare.."\r\n"
                  sh[user.sName] = share
                  time = 1
               end
            else
               tmp = tmp..line.."\r\n"
            end
         end
      end
      readfrom()
      writeto(sharertxt)
      write(tmp)
      writeto()
   end
end
Title:
Post by: jiten on 27 May, 2005, 08:13:06
There's a similar script I posted some while ago.
Check this (http://board.univ-angers.fr/thread.php?threadid=4273&boardid=28&sid=6f825474c37539f1c9c40154fce6b240) link.

Cheers
Title: Re share controler
Post by: damo on 27 May, 2005, 12:05:22
i did try that one but it disconected all me users
Title:
Post by: jiten on 27 May, 2005, 12:41:47
Here goes a fast one then:
-- Lua 5 version by jiten
--Requested by jsjen
--Made by nErBoS

Bot = "Share-Controler"

sharertxt = "shares.txt" --Will be created in the script folder
sh = {}

function Main()
frmHub:RegBot(Bot)
end

function NewUserConnected(user, data)
local share = user.iShareSize
local i = string.format("%0.2f", tonumber(share)/(1024*1024*1024))
CheckShare(user, i)
end

OpConnected = NewUserConnected

function ChatArrival(user, data)
local data = string.sub(data, 1, -2)
local s,e,cmd = string.find(data,"%b<>%s+(%S+)")
if cmd == "!sgrw" then
if (user.bOperator) then
local s,e,who = string.find(data,"%b<>%s+%S+%s+(%S+)")
if (who == nil or who == "") then
user:SendPM(Bot, "Syntax Error, !sgrw , you must write a name.")
else
user:SendPM(Bot, CheckUser(who))
end
else
user:SendPM(Bot, "You don?t have permission to use this command.")
end
return 1
end
end

ToArrival = ChatArrival

function CheckUser(user)
local tmp = ""
if (Verify(sharertxt) == nil) then
tmp = tmp.."the file hasn't been created yet."
else
local e = io.open(sharertxt,"r")
while 1 do
local line = e:read("*l")
if (line == nil) then
tmp = tmp.."The user "..user.." wasn't found in the list, have you write the right name ?"
break
else
local s,e,who,lshare, fshare = string.find(line, "(%S+)%s+%&%s+(%S+)%s+&%s+(%S+)")
if (who ~= nil and string.lower(who) == string.lower(user) ) then
if (GetItemByName(user) ~= nil) then
tmp = tmp.."The user "..user.." is sharing "..lshare.." GB his last share was "..fshare.." GB."
else
tmp = tmp.."The user "..user.." has shared "..lshare.." GB."
end
break
end
end
end
e:read()
e:close()
end
return tmp
end


function CheckShare(user, share)
local tmp, time = "",0
if (Verify(sharertxt) == nil) then
local f = io.open(sharertxt,"w+")
f:write(user.sName.." & "..share.." & 0\r\n")
f:close()
else
local g = io.open(sharertxt,"r")
while 1 do
local line = g:read("*l")
if (line == nil) then
if (time == 0) then
tmp = tmp..user.sName.." & "..share.." & 0\r\n"
end
break
else
local s,e,who,nshare = string.find(line, "(%S+)%s+%&%s+(%S+)%s+&%s+%S+")
if (who ~= nil and string.lower(who) == string.lower(user.sName)) then
if (tonumber(nshare) > tonumber(share)) then
SendPmToOps(Bot, "The user "..user.sName.." has least share then his last loggin.")
SendPmToOps(Bot, "He had "..nshare.." GB and now he has "..share.." GB.")
tmp = tmp..user.sName.." & "..share.." & "..nshare.."\r\n"
sh[user.sName] = share
time = 1
elseif (tonumber(nshare) < tonumber(share)) then
SendPmToOps(Bot, "The user "..user.sName.." has more share then his last loggin.")
SendPmToOps(Bot, "He had "..nshare.." GB and now he has "..share.." GB.")
tmp = tmp..user.sName.." & "..share.." & "..nshare.."\r\n"
sh[user.sName] = share
time = 1
elseif (tonumber(nshare) == tonumber(share)) then
tmp = tmp..user.sName.." & "..share.." & "..nshare.."\r\n"
sh[user.sName] = share
time = 1
end
else
tmp = tmp..line.."\r\n"
end
end
end
g:read()
g:close()
local h = io.open(sharertxt,"w+")
h:write(tmp)
h:close()
end
end

function Verify(filename)
local f = io.open(filename, "r")
if f then
f:close()
return true
end
end