Author Topic: UserInfo Script [API 2]  (Read 11840 times)

0 Members and 1 Guest are viewing this topic.

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
UserInfo Script [API 2]
« on: 05 March, 2008, 20:06:23 »
Code: [Select]
--[[
      
      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
« Last Edit: 22 July, 2009, 18:58:27 by speedX »
Thanking You,

speedX

PtokaX forum

UserInfo Script [API 2]
« on: 05 March, 2008, 20:06:23 »

Offline 11hh

  • Newbie
  • *
  • Posts: 8
  • Karma: +2/-1
Re: UserInfo Script [API 2]
« Reply #1 on: 11 March, 2008, 04:21:52 »
!userinfo nick --> <PtokaX> Please specify a nick. :o

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
Re: UserInfo Script [API 2]
« Reply #2 on: 11 March, 2008, 14:18:26 »
!userinfo nick --> <PtokaX> Please specify a nick. :o
???

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

speedX

Offline osse

  • Member
  • ***
  • Posts: 44
  • Karma: +0/-0
Re: UserInfo Script [API 2]
« Reply #3 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 ??
« Last Edit: 24 March, 2008, 21:52:01 by osse »

Offline Psycho_Chihuahua

  • Systemspecialist IT
  • Emperor
  • **
  • Posts: 1 054
  • Karma: +112/-1
  • I am wherever i want to be
    • PtokaX Luaboard
Re: UserInfo Script [API 2]
« Reply #4 on: 24 March, 2008, 22:56:15 »
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
Code: [Select]
        Core.SendPmToNick(user.sNick,tSettings.sBot,msg)
to
Code: [Select]
        Core.SendToAll(user.sNick,tSettings.sBot,msg)

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

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
Re: UserInfo Script [API 2]
« Reply #5 on: 25 March, 2008, 05:45:00 »
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

Offline osse

  • Member
  • ***
  • Posts: 44
  • Karma: +0/-0
Re: UserInfo Script [API 2]
« Reply #6 on: 25 March, 2008, 09:04:05 »
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

Offline Daywalker?

  • Scripter
  • Member
  • ******
  • Posts: 45
  • Karma: +9/-9
Re: UserInfo Script [API 2]
« Reply #7 on: 25 March, 2008, 09:46:52 »
Maybe you are looking for this kind of script then:

http://board.ptokax.ath.cx/index.php?topic=7379.0

Offline osse

  • Member
  • ***
  • Posts: 44
  • Karma: +0/-0
Re: UserInfo Script [API 2]
« Reply #8 on: 25 March, 2008, 09:56:17 »
Thnx ......:D:D:D

Offline shardana

  • Newbie
  • *
  • Posts: 6
  • Karma: +1/-1
Re: UserInfo Script [API 2]
« Reply #9 on: 07 April, 2008, 14:51:23 »
It would be wonderful to implement ip search in the database... can it be possible?
« Last Edit: 07 April, 2008, 18:07:41 by shardana »

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
Re: UserInfo Script [API 2]
« Reply #10 on: 07 April, 2008, 18:56:32 »
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

Offline shardana

  • Newbie
  • *
  • Posts: 6
  • Karma: +1/-1
Re: UserInfo Script [API 2]
« Reply #11 on: 08 April, 2008, 15:21:03 »
Very good :) I attend it with anxiety. Thanks in advance!

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
Re: UserInfo Script [API 2]
« Reply #12 on: 08 April, 2008, 22:07:23 »
Here, sorry for the delay. Post bugs if any....

Code: [Select]
--[[
      
      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
« Last Edit: 22 July, 2009, 18:59:10 by speedX »
Thanking You,

speedX

Offline shardana

  • Newbie
  • *
  • Posts: 6
  • Karma: +1/-1
Re: UserInfo Script [API 2]
« Reply #13 on: 09 April, 2008, 14:16:40 »
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!
« Last Edit: 09 April, 2008, 14:20:12 by shardana »

Offline rolipoli

  • Junior Member
  • **
  • Posts: 19
  • Karma: +0/-1
  • Transilvania-Erd?ly
Re: UserInfo Script [API 2]
« Reply #14 on: 10 April, 2008, 13:05:47 »
I've get this "Syntax UserInfo.lua:65:bad argument #1 to 'find' (string expected,got nil)".

Offline bigmark

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
Re: UserInfo Script [API 2]
« Reply #15 on: 04 January, 2009, 04:37:35 »
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.

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
Re: UserInfo Script [API 2]
« Reply #16 on: 04 January, 2009, 07:35:57 »
hm...When do u get that error??
Thanking You,

speedX

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
Re: UserInfo Script [API 2]
« Reply #17 on: 22 July, 2009, 20:59:13 »
Code: [Select]
--[[
     
      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
« Last Edit: 23 July, 2009, 08:56:44 by speedX »
Thanking You,

speedX

Offline BobyJ

  • Junior Member
  • **
  • Posts: 19
  • Karma: +1/-0
Re: UserInfo Script [API 2]
« Reply #18 on: 18 January, 2014, 14:42:32 »
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:
« Last Edit: 23 January, 2014, 10:25:40 by BobyJ »

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
Re: UserInfo Script [API 2]
« Reply #19 on: 26 May, 2014, 01:11:46 »
Fixed the possible null value. Hope this version works for you.

Code: [Select]
--[[
     
      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
« Last Edit: 02 October, 2014, 22:13:58 by speedX »
Thanking You,

speedX

Offline BobyJ

  • Junior Member
  • **
  • Posts: 19
  • Karma: +1/-0
Re: UserInfo Script [API 2]
« Reply #20 on: 31 May, 2014, 14:43:52 »
Thanks speedX  :D
I have made little changes, because the right click menu don't work for me. Here is it:

Code: [Select]
--[[
     
      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!
« Last Edit: 04 June, 2014, 12:18:53 by BobyJ »

Offline BobyJ

  • Junior Member
  • **
  • Posts: 19
  • Karma: +1/-0
Re: UserInfo Script [API 2]
« Reply #21 on: 25 August, 2015, 00:02:09 »
Is there a way that the script displays Size of exact share in bytes (from MyInfo string)?

Offline the-master

  • Triple Ace
  • **
  • Posts: 221
  • Karma: +10/-15
Re: UserInfo Script [API 2]
« Reply #22 on: 29 August, 2015, 07:43:19 »
yes, change ..ShareConverter(data[12]) into ..data[12]
keep on sharing :)
dchub://kickincountryhub.no-ip.org

Offline BobyJ

  • Junior Member
  • **
  • Posts: 19
  • Karma: +1/-0
Re: UserInfo Script [API 2]
« Reply #23 on: 02 September, 2015, 14:32:39 »
Thanks the-master :)  Will try it and respond.  :yes:

PtokaX forum

Re: UserInfo Script [API 2]
« Reply #23 on: 02 September, 2015, 14:32:39 »