Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) > Finished Scripts

UserInfo Script [API 2]

(1/5) > >>

speedX:

--- Code: -----[[
      
      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

--- End code ---

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

--- End quote ---
???

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

osse:
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 ??

--- End quote ---

My Guess would be to change Line

--- Code: ---        Core.SendPmToNick(user.sNick,tSettings.sBot,msg)

--- End code ---
to

--- Code: ---        Core.SendToAll(user.sNick,tSettings.sBot,msg)

--- End code ---

but i'm no scripter so i might be wrong

Navigation

[0] Message Index

[#] Next page

Go to full version