UserInfo Script [API 2]
 

UserInfo Script [API 2]

Started by speedX, 05 March, 2008, 20:06:23

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

speedX

--[[
     
     Userinfo Script [API 2]  (5/03/08)
     Made by speedX
     Version 1.0
     
     Description:
       Adds userdata to database
       You can find userinfo on input of command
     
]]--
tSettings = {
-- Bot Name
sBot = SetMan.GetString(21),
-- File Name
fFile = "userinfo.tbl",
-- Command
infocommand = "userinfo",
-- Permissions: 1 = Allow; 0 = Dont allow
Permission = {
   [-1] = 0, -- Unreg Users
[0] = 1, -- Masters
[1] = 1, -- Operators
[2] = 0, -- VIPs
[3] = 0, -- Regs
}
}
function OnStartup()
 if loadfile(tSettings.fFile) ~= nil then
dofile(tSettings.fFile)
else
   UserDB = {}
SaveToFile(tSettings.fFile,UserDB,"UserDB")
end
end
UserConnected = function(user)
 Core.GetUserAllData(user)
   UserDB[user.sNick] = {user.sIP or "N/A",user.sDescription or "N/A",user.sClient or "N/A",user.sClientVersion,user.sMode or "N/A",user.sTag or "N/A",user.iHubs or "N/A",user.iSlots or "N/A",user.sConnection or "N/A",user.sEmail or "N/A",user.iShareSize or "N/A",os.date()}
   SaveToFile(tSettings.fFile,UserDB,"UserDB")
   if tSettings.Permission[user.iProfile] and tSettings.Permission[user.iProfile] == 1 then
     Core.SendToNick(user.sNick,"$UserCommand 1 3 Get UserInfo$<%[mynick]> +userinfo %[line:Nick]&#124;|")
   end
end
OpConnected,RegConnected = UserConnected,UserConnected
ChatArrival = function(user,data)
 local _,_,data = string.find(data,"%b<>%s*(.*)|")
 local _,_,cmd = string.find(data,"%p(%S+)")
 if cmd then
   if cmd:lower() == tSettings.infocommand then
     if tSettings.Permission[user.iProfile] and tSettings.Permission[user.iProfile] == 1 then
     local _,_,nick = string.find(data,"%p%S+ (%w+)")
     if nick then
     local tNick,sReg,border,msg,prof = CheckUser(nick),RegMan.GetReg(nick)
     if sReg then
       prof = ProfMan.GetProfile(sReg.iProfile).sProfileName
     else
       prof = "Unregistered"
     end
       if tNick then
       Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Searching for "..nick.." in database......")
       border = "\r\n\t"..string.rep("=",50).."\r\n\t"
       msg = border.."\t\tInfo on "..nick.."\r\n\t"..string.rep("-",100)
       msg = msg.."\r\n\tName :\t\t"..nick
       msg = msg.."\r\n\tIP :\t\t"..tNick[1]
       msg = msg.."\r\n\tProfile :\t\t"..prof
       msg = msg.."\r\n\tDescription :\t"..tNick[2]
       msg = msg.."\r\n\tClient :\t\t"..tNick[3].." "..tNick[4]
       msg = msg.."\r\n\tMode :\t\t"..tNick[5]
       msg = msg.."\r\n\tTag :\t\t"..tNick[6]
       msg = msg.."\r\n\tHubs :\t\t"..tNick[7]
       msg = msg.."\r\n\tSlots :\t\t"..tNick[8]
       msg = msg.."\r\n\tConnection :\t"..tNick[9]
       msg = msg.."\r\n\tE-Mail :\t\t"..tNick[10]
       msg = msg.."\r\n\tShare :\t\t"..ShareConverter(tNick[11])
       if Core.GetUser(nick) then
         msg = msg.."\r\n\tStatus :\t\tONLINE"
       else
         msg = msg.."\r\n\tStatus :\t\tOFFLINE"
         msg = msg.."\r\n\tLastseen :\t"..tNick[12]
       end
       msg = msg..border
       Core.SendPmToNick(user.sNick,tSettings.sBot,msg)
       Clear()
       return true
       else
         Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..nick.." is not in the database.")
         return true
       end
     else
       Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Please specify a nick.")
       return true
     end
     end
   end
 end
end
CheckUser = function(nick)
 for i,_ in pairs(UserDB) do
   if i:lower() == nick:lower() then
     return UserDB[i]
   end
 end
end
ShareConverter = function(x)
 if x < 1024 then
   unit = "B"
 elseif x < 1048576 then
   x = x/1024
   unit = "KB"
 elseif x < 1073741824 then
   x = x/1048576
   unit = "MB"
 elseif x < 1099511627776 then
   x = x/1073741824
   unit = "GB"
 elseif x > 1099511627776 then
   x = x/1099511627776
   unit = "TB"
 end
 return string.format("%.2f "..unit,x)
end
Clear = function()
collectgarbage()
io.flush()
end
Save_Serialize = function(tTable, sTableName, hFile, sTab)
sTab = sTab or "";
hFile:write(sTab..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
Save_Serialize(value, sKey, hFile, sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
hFile:write( sTab.."\t"..sKey.." = "..sValue);
end
hFile:write( ",\n");
end
hFile:write( sTab.."}");
end
SaveToFile = function(file,table , tablename )
local hFile = io.open(file , "w")
Save_Serialize(table, tablename, hFile);
hFile:close()
Clear()
end
Thanking You,

speedX

11hh

!userinfo nick --> <PtokaX> Please specify a nick. :o

speedX

Quote from: 11hh on 11 March, 2008, 04:21:52
!userinfo nick --> <PtokaX> Please specify a nick. :o
???

!userinfo nick --> [18:47] <PtokaX> nick is not in the database. 
Thanking You,

speedX

osse

#3
If I want the information to averyone who enjoy the hub ?? just to the user so he can see his information.
How can I do it ??

Psycho_Chihuahua

Quote from: osse on 24 March, 2008, 21:47:02
If I want the information to averyone who enjoy the hub ?? just to the user so he can see his information.
How can I do it ??

My Guess would be to change Line
        Core.SendPmToNick(user.sNick,tSettings.sBot,msg)

to
        Core.SendToAll(user.sNick,tSettings.sBot,msg)


but i'm no scripter so i might be wrong
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

speedX

Quote from: osse on 24 March, 2008, 21:47:02
If I want the information to averyone who enjoy the hub ?? just to the user so he can see his information.
How can I do it ??

You mean that everyuser in the hub should be able to see his own information??
Thanking You,

speedX

osse

Quote from: speedX on 25 March, 2008, 05:45:00
You mean that everyuser in the hub should be able to see his own information??

I mean When you enjoy the HUB your information ( IP , Nick, share, slots, client, Hub and more )  appear automatically just for the user who enjoy the HUB.

Thnx for answer.. and help ;D

Daywalker?


osse


shardana

#9
It would be wonderful to implement ip search in the database... can it be possible?

speedX

Quote from: shardana on 07 April, 2008, 14:51:23
It would be wonderful to implement ip search in the database... can it be possible?

Yes, it will be added in next version....

Thanking You,

speedX

shardana

Very good :) I attend it with anxiety. Thanks in advance!

speedX

#12
Here, sorry for the delay. Post bugs if any....

--[[
     
     Userinfo Script [API 2]  (5/03/08)
     Made by speedX
     Version 1.1
     --------------------------------------------
     Changes:
       Added: Command to search database with IP. (Requested by shardana)
     --------------------------------------------
     
     Description:
       Adds userdata to database
       You can find userinfo on input of command
     
]]--
tSettings = {
-- Bot Name
sBot = SetMan.GetString(21),
-- File Name
fFile = "userinfo.tbl",
-- Command
infocommand = "userinfo",
ipcommand = "userip",
-- Permissions: 1 = Allow; 0 = Dont allow
Permission = {
   [-1] = 0, -- Unreg Users
[0] = 1, -- Masters
[1] = 1, -- Operators
[2] = 0, -- VIPs
[3] = 0, -- Regs
}
}
function OnStartup()
 if loadfile(tSettings.fFile) ~= nil then
dofile(tSettings.fFile)
else
   UserDB = {}
SaveToFile(tSettings.fFile,UserDB,"UserDB")
end
end
UserConnected = function(user)
 Core.GetUserAllData(user)
 Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Welcome "..user.sNick..", speedX's UserInfo 1.1 is enabled. RightClick for menu.")
   UserDB[user.sNick] = {user.sNick,user.sIP or "N/A",user.sDescription or "N/A",user.sClient or "N/A",user.sClientVersion,user.sMode or "N/A",user.sTag or "N/A",user.iHubs or "N/A",user.iSlots or "N/A",user.sConnection or "N/A",user.sEmail or "N/A",user.iShareSize or "N/A",os.date()}
   SaveToFile(tSettings.fFile,UserDB,"UserDB")
   if tSettings.Permission[user.iProfile] and tSettings.Permission[user.iProfile] == 1 then
     Core.SendToNick(user.sNick,"$UserCommand 1 3 UserInfo\\Get UserInfo$<%[mynick]> +"..tSettings.infocommand.." %[line:Nick]&#124;|")
     Core.SendToNick(user.sNick,"$UserCommand 1 3 UserInfo\\Get UserIP$<%[mynick]> +"..tSettings.ipcommand.." %[line:IP]&#124;|")
   end
end
OpConnected,RegConnected = UserConnected,UserConnected
ChatArrival = function(user,data)
 local _,_,data = string.find(data,"%b<>%s*(.*)|")
 local _,_,cmd = string.find(data,"%p(%S+)")
 if cmd then
   if cmd:lower() == tSettings.infocommand then
     if tSettings.Permission[user.iProfile] and tSettings.Permission[user.iProfile] == 1 then
     local _,_,nick = string.find(data,"%p%S+ (%S+)")
     if nick then
     local tNick = CheckUser(nick)
       if tNick then
         Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Searching for "..nick.." in database......")
         Core.SendPmToNick(user.sNick,tSettings.sBot,Data(nick,nil,tNick))
         Clear()
         return true
       else
         Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..nick.." is not in the database.")
         return true
       end
     else
       Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Please specify a nick. Use +"..tSettings.infocommand.." <nick>")
       return true
     end
     end
   elseif cmd:lower() == tSettings.ipcommand then
     if tSettings.Permission[user.iProfile] and tSettings.Permission[user.iProfile] == 1 then
     local _,_,ip = string.find(data,"%p%S+ (%d+.%d+.%d+.%d+)")
     local reply,msg = 0,""
     if ip then
     Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Searching for IP "..ip.." in database......")
       for i,v in pairs(UserDB) do
         if v[2] == ip then
           msg = msg.."\r\n"..Data(i,ip,v)
           reply = reply + 1
         end
       end
       Clear()
       if reply == 0 then
         Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> IP: "..ip.." is not in the database.")
       else
         Core.SendPmToNick(user.sNick,tSettings.sBot,msg)
       end
       return true
     else
       Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Invalid IP. Use +"..tSettings.ipcommand.." <ip>")
       return true
     end
     end
   end
 end
end
Data = function(nick,ip,data)
 local sReg,border,msg,prof = RegMan.GetReg(nick)
 if sReg then
       prof = ProfMan.GetProfile(sReg.iProfile).sProfileName
 else
       prof = "Unregistered"
 end
 border = "\r\n\t"..string.rep("=",50).."\r\n\t"
 if ip then
   msg = border.."\t\tInfo on IP: "..ip.."\r\n\t"..string.rep("-",100)
 else
   msg = border.."\t\tInfo on "..nick.."\r\n\t"..string.rep("-",100)
 end
 msg = msg.."\r\n\tName :\t\t"..data[1]
 msg = msg.."\r\n\tIP :\t\t"..data[2]
 msg = msg.."\r\n\tProfile :\t\t"..prof
 msg = msg.."\r\n\tDescription :\t"..data[3]
 msg = msg.."\r\n\tClient :\t\t"..data[4].." "..data[5]
 msg = msg.."\r\n\tMode :\t\t"..data[6]
 msg = msg.."\r\n\tTag :\t\t"..data[7]
 msg = msg.."\r\n\tHubs :\t\t"..data[8]
 msg = msg.."\r\n\tSlots :\t\t"..data[9]
 msg = msg.."\r\n\tConnection :\t"..data[10]
 msg = msg.."\r\n\tE-Mail :\t\t"..data[11]
 msg = msg.."\r\n\tShare :\t\t"..ShareConverter(data[12])
 if Core.GetUser(nick) then
   msg = msg.."\r\n\tStatus :\t\tONLINE"
 else
   msg = msg.."\r\n\tStatus :\t\tOFFLINE"
   msg = msg.."\r\n\tLastseen :\t"..data[13]
 end
 msg = msg..border
 return msg
end
CheckUser = function(nick)
 for i,_ in pairs(UserDB) do
   if i:lower() == nick:lower() then
     return UserDB[i]
   end
 end
end
ShareConverter = function(x)
 if x < 1024 then
   unit = "B"
 elseif x < 1048576 then
   x = x/1024
   unit = "KB"
 elseif x < 1073741824 then
   x = x/1048576
   unit = "MB"
 elseif x < 1099511627776 then
   x = x/1073741824
   unit = "GB"
 elseif x > 1099511627776 then
   x = x/1099511627776
   unit = "TB"
 end
 return string.format("%.2f "..unit,x)
end
Clear = function()
collectgarbage()
io.flush()
end
Save_Serialize = function(tTable, sTableName, hFile, sTab)
sTab = sTab or "";
hFile:write(sTab..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
Save_Serialize(value, sKey, hFile, sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
hFile:write( sTab.."\t"..sKey.." = "..sValue);
end
hFile:write( ",\n");
end
hFile:write( sTab.."}");
end
SaveToFile = function(file,table , tablename )
local hFile = io.open(file , "w")
Save_Serialize(table, tablename, hFile);
hFile:close()
Clear()
end
Thanking You,

speedX

shardana

#13
Very thanks. It works perfectly but...
if there are two or more users with the same ip.. the script finds only one of these users ..it could inform of the presence of...
Thanks in advance!

rolipoli

I've get this "Syntax UserInfo.lua:65:bad argument #1 to 'find' (string expected,got nil)".

bigmark

I am getting this error
Error! - No User named [ username$MyINFO $ALL Bigmark owner of mayhem<++ V:0.706,M:A,H:0/1/12,S:2,L:84>$ $2$$554582566583$ ] online.

speedX

hm...When do u get that error??
Thanking You,

speedX

speedX

#17
--[[
     
      Userinfo Script [API 2]  (5/03/08)
      Made by speedX
      Version 1.2
      --------------------------------------------
      Changes:
        Added: Command to search database with IP. (Requested by shardana)
        Added: Shows info on user connect.
      --------------------------------------------
     
      Description:
        Adds userdata to database
        You can find userinfo on input of command
     
]]--
tSettings = {
-- Bot Name
sBot = SetMan.GetString(21),
-- Hub Name
sHub = SetMan.GetString(0),
-- File Name
fFile = "userinfo.tbl",
-- Command
infocommand = "userinfo",
ipcommand = "userip",
-- Show stats on Login?
bLogin = true,
-- Permissions: 1 = Allow; 0 = Dont allow
Permission = {
    [-1] = 0, -- Unreg Users
[0] = 1, -- Masters
[1] = 1, -- Operators
[2] = 0, -- VIPs
[3] = 0, -- Regs
}
}
function OnStartup()
  if loadfile(tSettings.fFile) ~= nil then
    dofile(tSettings.fFile)
  else
    UserDB = {}
    SaveToFile(tSettings.fFile,UserDB,"UserDB")
  end
end
UserConnected = function(user)
  Core.GetUserAllData(user)
  Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Welcome "..user.sNick..", speedX's UserInfo 1.2 is enabled. RightClick for menu.")
    UserDB[user.sNick] = {user.sNick,user.sIP or "N/A",user.sDescription or "N/A",user.sClient or "N/A",user.sClientVersion,user.sMode or "N/A",user.sTag or "N/A",user.iHubs or "N/A",user.iSlots or "N/A",user.sConnection or "N/A",user.sEmail or "N/A",user.iShareSize or "N/A",os.date()}
    SaveToFile(tSettings.fFile,UserDB,"UserDB")
    if tSettings.bLogin then
      local border = "\r\n\t"..string.rep("=-",30).."\r\n\t"
      local header = "Welcome to "..tSettings.sHub.."\r\n\t"..string.rep("=-",30)
      Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..border..header..Data(user.sNick,nil,UserDB[user.sNick])..border)
    end
    if tSettings.Permission[user.iProfile] and tSettings.Permission[user.iProfile] == 1 then
      Core.SendToNick(user.sNick,"$UserCommand 1 3 UserInfo\\Get UserInfo$<%[mynick]> +"..tSettings.infocommand.." %[line:Nick]&#124;|")
      Core.SendToNick(user.sNick,"$UserCommand 1 3 UserInfo\\Get UserIP$<%[mynick]> +"..tSettings.ipcommand.." %[line:IP]&#124;|")
    end
end
OpConnected,RegConnected = UserConnected,UserConnected
ChatArrival = function(user,data)
  local _,_,cmd = string.find(data,"%b<> %p(%w+)")
  if cmd then
    if cmd:lower() == tSettings.infocommand then
      if tSettings.Permission[user.iProfile] and tSettings.Permission[user.iProfile] == 1 then
      local _,_,nick = string.find(data,"%b<> %p%w+ (%S+)|")
      if nick then
      local tNick = CheckUser(nick)
        if tNick then
          Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Searching for "..nick.." in database......")
          local border = "\r\n\t"..string.rep("=",50).."\r\n\t"
          local header = "\t\tInfo on Nick: "..nick.."\r\n\t"..string.rep("-",100)
          Core.SendPmToNick(user.sNick,tSettings.sBot,border..header..Data(nick,nil,tNick)..border)
          Clear()
          return true
        else
          Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..nick.." is not in the database.")
          return true
        end
      else
        Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Please specify a nick. Use +"..tSettings.infocommand.." <nick>")
        return true
      end
      end
    elseif cmd:lower() == tSettings.ipcommand then
      if tSettings.Permission[user.iProfile] and tSettings.Permission[user.iProfile] == 1 then
      local _,_,ip = string.find(data,"%b<> %p%w+ (%d+.%d+.%d+.%d+)|")
      local iCount,msg = 0,""
      if ip then
      Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Searching for IP "..ip.." in database......")
        for i,v in pairs(UserDB) do
          if v[2] == ip then
            msg = msg.."\r\n"..Data(i,ip,v)
            iCount = iCount + 1
          end
        end
        Clear()
        if iCount == 0 then
          Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> IP: "..ip.." is not in the database.")
        else
          local border = "\r\n\t"..string.rep("=",50).."\r\n\t"
          local header = "\t\tInfo on IP: "..ip.."\r\n\t"..string.rep("-",100)
          Core.SendPmToNick(user.sNick,tSettings.sBot,border..header..msg..border)
        end
        return true
      else
        Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Invalid IP. Use +"..tSettings.ipcommand.." <ip>")
        return true
      end
      end
    end
  end
end
Data = function(nick,ip,data)
  local sReg,msg,prof = RegMan.GetReg(nick),""
  if sReg then
        prof = ProfMan.GetProfile(sReg.iProfile).sProfileName
  else
        prof = "Unregistered"
  end
  msg = msg.."\r\n\tName :\t\t"..data[1]
  msg = msg.."\r\n\tIP :\t\t"..data[2]
  msg = msg.."\r\n\tProfile :\t\t"..prof
  msg = msg.."\r\n\tDescription :\t"..data[3]
  msg = msg.."\r\n\tClient :\t\t"..data[4].." "..data[5]
  msg = msg.."\r\n\tMode :\t\t"..data[6]
  msg = msg.."\r\n\tTag :\t\t"..data[7]
  msg = msg.."\r\n\tHubs :\t\t"..data[8]
  msg = msg.."\r\n\tSlots :\t\t"..data[9]
  msg = msg.."\r\n\tConnection :\t"..data[10]
  msg = msg.."\r\n\tE-Mail :\t\t"..data[11]
  msg = msg.."\r\n\tShare :\t\t"..ShareConverter(data[12])
  if Core.GetUser(nick) then
    msg = msg.."\r\n\tStatus :\t\tONLINE"
  else
    msg = msg.."\r\n\tStatus :\t\tOFFLINE"
    msg = msg.."\r\n\tLastseen :\t"..data[13]
  end
  return msg
end
CheckUser = function(nick)
  for i,_ in pairs(UserDB) do
    if i:lower() == nick:lower() then
      return UserDB[i]
    end
  end
end
ShareConverter = function(x)
  if x < 1024 then
    unit = "B"
  elseif x < 1048576 then
    x = x/1024
    unit = "KB"
  elseif x < 1073741824 then
    x = x/1048576
    unit = "MB"
  elseif x < 1099511627776 then
    x = x/1073741824
    unit = "GB"
  elseif x > 1099511627776 then
    x = x/1099511627776
    unit = "TB"
  end
  return string.format("%.2f "..unit,x)
end
Clear = function()
collectgarbage()
io.flush()
end
Save_Serialize = function(tTable, sTableName, hFile, sTab)
sTab = sTab or "";
hFile:write(sTab..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
Save_Serialize(value, sKey, hFile, sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
hFile:write( sTab.."\t"..sKey.." = "..sValue);
end
hFile:write( ",\n");
end
hFile:write( sTab.."}");
end
SaveToFile = function(file,table , tablename )
local hFile = io.open(file , "w")
Save_Serialize(table, tablename, hFile);
hFile:close()
Clear()
end
Thanking You,

speedX

BobyJ

#18
Big thanks speedX. It works great on PtokaX 0.5.0.0!  :yes:

P.S.
Unfortunately yesterday gave me this error:
[19:51:01] Syntax D:\0.5.0.0-Lua5.1.5-x64\scripts\UserInfo v.1.2.lua:137: attempt to concatenate field '?' (a nil value)

Can anyone fix this and help me please?
Thanks in advance!
:yes:

speedX

#19
Fixed the possible null value. Hope this version works for you.

--[[
     
      Userinfo Script [API 2]  (5/03/08)
      Made by speedX
      Version 1.3
      --------------------------------------------
      Changes:
        Added: Command to search database with IP. (Requested by shardana)
        Added: Shows info on user connect.
        Fixed: Possible null field value.
      --------------------------------------------
     
      Description:
        Adds userdata to database
        You can find userinfo on input of command
     
]]--
tSettings = {
-- Bot Name
sBot = SetMan.GetString(21),
-- Hub Name
sHub = SetMan.GetString(0),
-- File Name
fFile = "userinfo.tbl",
-- Command
infocommand = "userinfo",
ipcommand = "userip",
-- Show stats on Login?
bLogin = true,
-- Permissions: 1 = Allow; 0 = Dont allow
Permission = {
    [-1] = 0, -- Unreg Users
[0] = 1, -- Masters
[1] = 1, -- Operators
[2] = 0, -- VIPs
[3] = 0, -- Regs
}
}
function OnStartup()
  if loadfile(tSettings.fFile) ~= nil then
    dofile(tSettings.fFile)
  else
    UserDB = {}
    SaveToFile(tSettings.fFile,UserDB,"UserDB")
  end
end
UserConnected = function(user)
  Core.GetUserAllData(user)
  Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Welcome "..user.sNick..", speedX's UserInfo 1.2 is enabled. RightClick for menu.")
    UserDB[user.sNick] = {user.sNick,user.sIP or "N/A",user.sDescription or "N/A",user.sClient or "N/A",user.sClientVersion or "N/A",user.sMode or "N/A",user.sTag or "N/A",user.iHubs or "N/A",user.iSlots or "N/A",user.sConnection or "N/A",user.sEmail or "N/A",user.iShareSize or "N/A",os.date()}
    SaveToFile(tSettings.fFile,UserDB,"UserDB")
    if tSettings.bLogin then
      local border = "\r\n\t"..string.rep("=-",30).."\r\n\t"
      local header = "Welcome to "..tSettings.sHub.."\r\n\t"..string.rep("=-",30)
      Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..border..header..Data(user.sNick,nil,UserDB[user.sNick])..border)
    end
    if tSettings.Permission[user.iProfile] and tSettings.Permission[user.iProfile] == 1 then
      Core.SendToNick(user.sNick,"$UserCommand 1 3 UserInfo\\Get UserInfo$<%[mynick]> +"..tSettings.infocommand.." %[line:Nick]&#124;|")
      Core.SendToNick(user.sNick,"$UserCommand 1 3 UserInfo\\Get UserIP$<%[mynick]> +"..tSettings.ipcommand.." %[line:IP]&#124;|")
    end
end
OpConnected,RegConnected = UserConnected,UserConnected
ChatArrival = function(user,data)
  local _,_,cmd = string.find(data,"%b<> %p(%w+)")
  if cmd then
    if cmd:lower() == tSettings.infocommand then
      if tSettings.Permission[user.iProfile] and tSettings.Permission[user.iProfile] == 1 then
      local _,_,nick = string.find(data,"%b<> %p%w+ (%S+)|")
      if nick then
      local tNick = CheckUser(nick)
        if tNick then
          Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Searching for "..nick.." in database......")
          local border = "\r\n\t"..string.rep("=",50).."\r\n\t"
          local header = "\t\tInfo on Nick: "..nick.."\r\n\t"..string.rep("-",100)
          Core.SendPmToNick(user.sNick,tSettings.sBot,border..header..Data(nick,nil,tNick)..border)
          Clear()
          return true
        else
          Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..nick.." is not in the database.")
          return true
        end
      else
        Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Please specify a nick. Use +"..tSettings.infocommand.." <nick>")
        return true
      end
      end
    elseif cmd:lower() == tSettings.ipcommand then
      if tSettings.Permission[user.iProfile] and tSettings.Permission[user.iProfile] == 1 then
      local _,_,ip = string.find(data,"%b<> %p%w+ (%d+.%d+.%d+.%d+)|")
      local iCount,msg = 0,""
      if ip then
      Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Searching for IP "..ip.." in database......")
        for i,v in pairs(UserDB) do
          if v[2] == ip then
            msg = msg.."\r\n"..Data(i,ip,v)
            iCount = iCount + 1
          end
        end
        Clear()
        if iCount == 0 then
          Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> IP: "..ip.." is not in the database.")
        else
          local border = "\r\n\t"..string.rep("=",50).."\r\n\t"
          local header = "\t\tInfo on IP: "..ip.."\r\n\t"..string.rep("-",100)
          Core.SendPmToNick(user.sNick,tSettings.sBot,border..header..msg..border)
        end
        return true
      else
        Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Invalid IP. Use +"..tSettings.ipcommand.." <ip>")
        return true
      end
      end
    end
  end
end
Data = function(nick,ip,data)
  local sReg,msg,prof = RegMan.GetReg(nick),""
  if sReg then
        prof = ProfMan.GetProfile(sReg.iProfile).sProfileName
  else
        prof = "Unregistered"
  end
  msg = msg.."\r\n\tName :\t\t"..data[1]
  msg = msg.."\r\n\tIP :\t\t"..data[2]
  msg = msg.."\r\n\tProfile :\t\t"..prof
  msg = msg.."\r\n\tDescription :\t"..data[3]
  msg = msg.."\r\n\tClient :\t\t"..data[4].." "..data[5]
  msg = msg.."\r\n\tMode :\t\t"..data[6]
  msg = msg.."\r\n\tTag :\t\t"..data[7]
  msg = msg.."\r\n\tHubs :\t\t"..data[8]
  msg = msg.."\r\n\tSlots :\t\t"..data[9]
  msg = msg.."\r\n\tConnection :\t"..data[10]
  msg = msg.."\r\n\tE-Mail :\t\t"..data[11]
  msg = msg.."\r\n\tShare :\t\t"..ShareConverter(data[12])
  if Core.GetUser(nick) then
    msg = msg.."\r\n\tStatus :\t\tONLINE"
  else
    msg = msg.."\r\n\tStatus :\t\tOFFLINE"
    msg = msg.."\r\n\tLastseen :\t"..data[13]
  end
  return msg
end
CheckUser = function(nick)
  for i,_ in pairs(UserDB) do
    if i:lower() == nick:lower() then
      return UserDB[i]
    end
  end
end
ShareConverter = function(x)
  if x < 1024 then
    unit = "B"
  elseif x < 1048576 then
    x = x/1024
    unit = "KB"
  elseif x < 1073741824 then
    x = x/1048576
    unit = "MB"
  elseif x < 1099511627776 then
    x = x/1073741824
    unit = "GB"
  elseif x > 1099511627776 then
    x = x/1099511627776
    unit = "TB"
  end
  return string.format("%.2f "..unit,x)
end
Clear = function()
collectgarbage()
io.flush()
end
Save_Serialize = function(tTable, sTableName, hFile, sTab)
sTab = sTab or "";
hFile:write(sTab..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
Save_Serialize(value, sKey, hFile, sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
hFile:write( sTab.."\t"..sKey.." = "..sValue);
end
hFile:write( ",\n");
end
hFile:write( sTab.."}");
end
SaveToFile = function(file,table , tablename )
local hFile = io.open(file , "w")
Save_Serialize(table, tablename, hFile);
hFile:close()
Clear()
end
Thanking You,

speedX

BobyJ

#20
Thanks speedX  :D
I have made little changes, because the right click menu don't work for me. Here is it:

--[[
     
      Userinfo Script [API 2]  (5/03/08)
      Made by speedX
      Version 1.3
      --------------------------------------------
      Changes:
        Added: Command to search database with IP. (Requested by shardana)
        Added: Shows info on user connect.
        Fixed: Possible null field value.
      --------------------------------------------
     
      Description:
        Adds userdata to database
        You can find userinfo on input of command
     
]]--
tSettings = {
-- Bot Name
sBot = SetMan.GetString(21),
-- Hub Name
sHub = SetMan.GetString(0),
-- File Name
fFile = "userinfo.tbl",
-- Command
infocommand = "userinfo",
ipcommand = "userip",
-- Show stats on Login?
bLogin = true,
-- Permissions: 1 = Allow; 0 = Dont allow
Permission = {
    [-1] = 0,   -- Unreg Users
        [0] = 1,    -- Masters
        [1] = 1,    -- Operators
        [2] = 0,    -- VIPs
        [3] = 0,    -- Regs
        }
}
function OnStartup()
  if loadfile(tSettings.fFile) ~= nil then
    dofile(tSettings.fFile)
  else
    UserDB = {}
    SaveToFile(tSettings.fFile,UserDB,"UserDB")
  end
end
UserConnected = function(user)
  Core.GetUserAllData(user)
  Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Welcome "..user.sNick..", speedX's UserInfo 1.2 is enabled. RightClick for menu.")
    UserDB[user.sNick] = {user.sNick,user.sIP or "N/A",user.sDescription or "N/A",user.sClient or "N/A",user.sClientVersion or "N/A",user.sMode or "N/A",user.sTag or "N/A",user.iHubs or "N/A",user.iSlots or "N/A",user.sConnection or "N/A",user.sEmail or "N/A",user.iShareSize or "N/A",os.date()}
    SaveToFile(tSettings.fFile,UserDB,"UserDB")
    if tSettings.bLogin then
      local border = "\r\n\t"..string.rep("=-",30).."\r\n\t"
      local header = "Welcome to "..tSettings.sHub.."\r\n\t"..string.rep("=-",30)
      Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..border..header..Data(user.sNick,nil,UserDB[user.sNick])..border)
    end
    if tSettings.Permission[user.iProfile] and tSettings.Permission[user.iProfile] == 1 then
      Core.SendToNick(user.sNick,"$UserCommand 1 3 UserInfo\\Get UserInfo$<%[mynick]> +"..tSettings.infocommand.." %[line:Nick]&#124;|")
      Core.SendToNick(user.sNick,"$UserCommand 1 3 UserInfo\\Get UserIP$<%[mynick]> +"..tSettings.ipcommand.." %[line:IP]&#124;|")
    end
end
OpConnected,RegConnected = UserConnected,UserConnected
ChatArrival = function(user,data)
  local _,_,cmd = string.find(data,"%b<> %p(%w+)")
  if cmd then
    if cmd:lower() == tSettings.infocommand then
      if tSettings.Permission[user.iProfile] and tSettings.Permission[user.iProfile] == 1 then
      local _,_,nick = string.find(data,"%b<> %p%w+ (%S+)|")
      if nick then
      local tNick = CheckUser(nick)
        if tNick then
          Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Searching for "..nick.." in database......")
          local border = "\r\n\t"..string.rep("=",50).."\r\n\t"
          local header = "\t\tInfo on Nick: "..nick.."\r\n\t"..string.rep("-",100)
          Core.SendPmToNick(user.sNick,tSettings.sBot,border..header..Data(nick,nil,tNick)..border)
          Clear()
          return true
        else
          Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..nick.." is not in the database.")
          return true
        end
      else
        Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Please specify a nick. Use +"..tSettings.infocommand.." <nick>")
        return true
      end
      end
    elseif cmd:lower() == tSettings.ipcommand then
      if tSettings.Permission[user.iProfile] and tSettings.Permission[user.iProfile] == 1 then
      local _,_,ip = string.find(data,"%b<> %p%w+ (%d+.%d+.%d+.%d+)|")
      local iCount,msg = 0,""
      if ip then
      Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Searching for IP "..ip.." in database......")
        for i,v in pairs(UserDB) do
          if v[2] == ip then
            msg = msg.."\r\n"..Data(i,ip,v)
            iCount = iCount + 1
          end
        end
        Clear()
        if iCount == 0 then
          Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> IP: "..ip.." is not in the database.")
        else
          local border = "\r\n\t"..string.rep("=",50).."\r\n\t"
          local header = "\t\tInfo on IP: "..ip.."\r\n\t"..string.rep("-",100)
          Core.SendPmToNick(user.sNick,tSettings.sBot,border..header..msg..border)
        end
        return true
      else
        Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> Invalid IP. Use +"..tSettings.ipcommand.." <ip>")
        return true
      end
      end
    end
  end
end
Data = function(nick,ip,data)
  local sReg,msg,prof = RegMan.GetReg(nick),""
  if sReg then
        prof = ProfMan.GetProfile(sReg.iProfile).sProfileName
  else
        prof = "Unregistered"
  end
  msg = msg.."\r\n\tName :\t\t"..data[1]
  msg = msg.."\r\n\tIP :\t\t"..data[2]
  msg = msg.."\r\n\tProfile :\t\t"..prof
  msg = msg.."\r\n\tDescription :\t"..data[3]
  msg = msg.."\r\n\tClient :\t\t"..data[4].." "..data[5]
  msg = msg.."\r\n\tMode :\t\t"..data[6]
  msg = msg.."\r\n\tTag :\t\t"..data[7]
  msg = msg.."\r\n\tHubs :\t\t"..data[8]
  msg = msg.."\r\n\tSlots :\t\t"..data[9]
  msg = msg.."\r\n\tConnection :\t"..data[10]
  msg = msg.."\r\n\tE-Mail :\t\t"..data[11]
  msg = msg.."\r\n\tShare :\t\t"..ShareConverter(data[12])
  if Core.GetUser(nick) then
    msg = msg.."\r\n\tStatus :\t\tONLINE"
  else
    msg = msg.."\r\n\tStatus :\t\tOFFLINE"
    msg = msg.."\r\n\tLastseen :\t"..data[13]
  end
  return msg
end
CheckUser = function(nick)
  for i,_ in pairs(UserDB) do
    if i:lower() == nick:lower() then
      return UserDB[i]
    end
  end
end
ShareConverter = function(x)
  if x < 1024 then
    unit = "B"
  elseif x < 1048576 then
    x = x/1024
    unit = "KB"
  elseif x < 1073741824 then
    x = x/1048576
    unit = "MB"
  elseif x < 1099511627776 then
    x = x/1073741824
    unit = "GB"
  elseif x > 1099511627776 then
    x = x/1099511627776
    unit = "TB"
  end
  return string.format("%.2f "..unit,x)
end
Clear = function()
    collectgarbage()
    io.flush()
end
Save_Serialize = function(tTable, sTableName, hFile, sTab)
    sTab = sTab or "";
    hFile:write(sTab..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
            Save_Serialize(value, sKey, hFile, sTab.."\t");
        else
            local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
            hFile:write( sTab.."\t"..sKey.." = "..sValue);
        end
        hFile:write( ",\n");
    end
    hFile:write( sTab.."}");
end
SaveToFile = function(file,table , tablename )
    local hFile = io.open(file , "w")
    Save_Serialize(table, tablename, hFile);
    hFile:close()
    Clear()
end



Will try it. Now waiting for the problematic user in the hub and will tell you how it works!  :D  ;)


P.S After few days of testing, it's work perfectly on PX 5.0.2 - LUA 5.1.5 :yes:
Big thanks speedX and cheers!

BobyJ

Is there a way that the script displays Size of exact share in bytes (from MyInfo string)?

the-master

yes, change ..ShareConverter(data[12]) into ..data[12]
keep on sharing :)

BobyJ

Thanks the-master :)  Will try it and respond.  :yes:

 
SMF spam blocked by CleanTalk