API Lua Methods - Verlihub/verlihub GitHub Wiki

Hub

VH:ParseCommand

This method parses any hub or script command as it is written by specified user with nick. pm specify if command has been sent in PM or MC.

     result, data = VH:ParseCommand(nick, command, pm)

Input parameters : 1= nick, 2= command, 3= pm

VH:SetConfig

Sets the config variable to the given value for the specified configuration type. Possible values for config type can be "config" for hub configuration or "pi_pluginname" (replace pluginame with the name of plugin). For example:

    result, error = VH:SetConfig("config","max_chat_msg","0")
    result, error = VH:SetConfig("pi_floodprot", "max_conn_per_ip", "2")

The first example will mute the main chat of the hub and the second one will change the max_conn_per_ip to two.

Input parameters: 1= config type, 2= variable, 3= value

VH:GetConfig

This method returns the value of a given variable for the specified configuration type. Possible values for config type can be "config" for hub configuration or "pi_pluginname" (replace pluginame with the name of plugin). For example:

    result, sBotname = VH:GetConfig("config","hub_security")
    result, sMaxConn = VH:GetConfig("pi_floodprot","max_conn_per_ip")

where sBotname will be the hub-security name in the first example.

Input parameters: 1= config type, 2= variable

VH:GetUsersCount

It returns the number of all online users. Bots and LUA registered bots will not be included in this list

VH:GetNickList

This method returns the nicklist which contains all users in the hub. For example:

    result, sNicklist = VH:GetNickList()

will store in sNicklist:

    $NickList user1$$user2$$user3$$usern$$

It will contain also the hub security and OPChat bots.

VH:GetTotalShareSize

It returns the total share size in byte.

VH:GetUpTime

This method returns the hub uptime in seconds. You can specify also the uptime unit to fit your needs:

     result, uptime = VH:GetUpTime()  -- return seconds, no arguments, backward compatibility
     result, uptime= VH:GetUpTime(1) -- return seconds, argument = 1, new style
     result, uptime= VH:GetUpTime(2) -- return milliseconds, argument = 2, new style

So you can simply implement this method in your script:

     result, sec = VH:GetUpTime ()
     if sec then
          return tonumber (sec) or 0
     else
          return 0
     end

Input parameters: 1= uptime unit

VH:GetHubIp

This method returns the hub IP address. For example:

    result, ip = VH:GetHubIp()

will return the value of listen_ip variable.

VH:GetHubSecAlias

This method returns the name of hub security bot. For example:

    result, security = VH:GetHubSecAlias()

will return the value of hub_security variable.

VH:StopHub

It stops/restart the hub with the given code error:

| Error code | Description| |-----------|------------|------------| |-1|Crash hub and dump core| |0|Quit hub| |1|Restart hub|

Input parameters: 1= code

VH:GetOPList

It returns the complete list of OPs including hub security and OPChat bots:

     $OpList [SU]root$$Mario$$VerliHub$$OpChat$$

VH:GetTopic

It returns the topic of the hub.

VH:SetTopic

This method will set the hub topic to the given message.

Input parameters: 1= topic

VH:GetVHCfgDir

Returns the path where configuration files are stored for the hub.

VH:SetTempRights

This method has not been implemented yet

VH:GetTempRights

This method has not been implemented yet

Users

VH:GetUserClass

Returns the numeric value of class between 0 and 10 for the given nick. For example:

    result, class = VH:GetUserClass (nick);
    if class < 5 then
           your code here .....
    end

Input parameters: 1= nick

VH:GetUserHost

Returns with the host of the given user's nick. For example:

    result, host = VH:GetUserHost (user)
    if host and (string.len (host) > 0) then
         return host
    else
         return nil
    end

Input parameters: 1= nick

VH:GetUserIP

Returns the IP address for the given nick. For example:

    result, userip = VH:GetUserIP (user)
    if userip and (string.len (userip) > 0) then
         return userip
    else
         return nil
    end

** Input parameters:** 1= nick

VH:GetUserCC

Returns the Country Code (CC) for the given nick. For example:

    result, usercc = VH:GetUserCC (user)
    if usercc or (usercc == "User not found") then
              return nil
    elseif usercc == "" then
      return "Not found"
    else
           return usercc
    end

Input parameters: 1= IP

VH:GetIPCC

Returns the Country Code (CC) for the given ip address. For example:

    result, usercc = VH:GetIPCC (ip)
    if usercc or (usercc == "User not found") then
            return nil
    elseif usercc == "" then
           return "Not found"
    else
            return usercc
    end

Input parameters: 1= ip

VH:RegBot

This method allows you to register a new bot in the hub with given nick, class, description, speed, email and share. For example:

    VH:RegBot ('Mario', 3, 'Hello users', 'DSL', '[email protected]', 0)

Input parameters: 1= nick, 2= class, 3= description, 4= speed, 5= email, 6= share

Old method: VH:AddRobot

VH:UnRegBot

This call remove the previously registered bot from the userlist with nick. For example:

    VH:UnRegBot ('Mario')

Input parameters: 1= nick Old method: VH:DelRobot

VH:EditBot

This call edit the previously registered bot from the userlist with the new values for nick, class, description, speed, email and share. For example:

    VH:EditBot ('Mario', 5, 'Hello users', 'DSL', '[email protected]', -1)

Input parameters: 1= nick, 2= class, 3= description, 4= speed, 5= email, 6= share

VH:IsBot

Check if given nick is bot or not.

Input parameters: 1= nick

VH:AddRegUser

Register a new user with given class number, nick, password and the nickname of the op that should register the user. For example:

    VH:AddRegUser ('Mario', '@32Hdd', 5, 'Owner')

will register a new Admin.

Input parameters: 1= nick, 2= password, 3= class, 4= op

VH:DelRegUser

Remove the register user with nick.

Input parameters: 1= nick

VH:IsUserOnline

Check if user with nick is online or not.

Input parameters: 1= nick

VH:GetMyINFO

It returns the full MyINFO string of the given nick. For example:

    result, myinfo = VH:GetMyINFO('Mario')
    if myinfo and (string.len (myinfo) > 0) then
        return myinfo
    else
        return nil
    end

will return a string like this:

    $MyINFO $ALL Mario [[2M/192K]]<++ V:0.698,M:A,H:0/0/1,S:3>[email protected]$152177393537$

Input parameters: 1= nick

VH:Disconnect

Use this to remove a user from the hub with nick. For example:

    VH:Disconnect ('Mario')

will drop the given user.

Input parameters: 1= nick

Old method: VH:CloseConnection or VH:DisconnectByName

VH:InUserSupports

Check if user with nick has the given flag in the $Supports message. The extension/flag can be one of the following parameter:

  • OpPlus
  • NoHello
  • NoGetINFO
  • DHT0
  • QuickList
  • BotINFO
  • ZPipe0
  • ChatOnly
  • MCTo
  • UserCommand

BotList

  • HubTopic
  • UserIP2
  • TTHSearch
  • Feed
  • ClientID
  • IN
  • BanMsg
  • TLS

Input parameters: 1= nick, 2= flag

VH:GetBots

Get the list of all registered bots. This method will return the following information for each bot:

  • Scriptname: the script that has loaded the bot
  • sNick: the nickname of the bot
  • iClass: the numerical class of the bot
  • iShare: current share
  • sMyINFO: the MyINFO CHECK THIS!

VH:GetBotList

TODO

Kicks & bans

VH:Ban

This method allow you to ban a user with the given nick with reason. You should also specify the op that should appear, the duration (in seconds) and the ban type flag. The flag can be one of the following parameter:

| Flag | Description| |-----------|------------|------------| |0|Nick and IP address are banned| |1|IP address is banned| |2|Nick is banned| |3|Range address is banned| |4|Host of level 1 is banned| |5|Host of level 2 is banned| |6|Host of level 3 is banned| |7|Share is banned| |8|Prefix of nick is banned| |9|Reverse host is banned|

For example:

      result, error = VH_Ban('Mario', 'Admin1', 'Faker!!', 86400, 1)

Input paramters: 1= nickname, 2= op, 3= reason, 4= duration, 5= flag

VH:KickUser

This method allow you to kick a user with the given nick with reason. You should also specify the op that should appear. For example:

      result, error = VH_KickUser('Admin1', 'Mario', 'Faker!!')
      result, error = VH_KickUser('Admin1', 'foobar', 'Spammer_BAN_2d')

As you can see from the second example you can also append the time at the end of the reason

Input paramters: 1= op, 2= nick, 3= reason

Messages

VH:SendToUser

Sends MyINFO data (i.e. $HubIsFull) to a user with given nickname. For example:

    VH:SendToUser("$ForceMove redirectarray:no-ip.org:3333|", 'Mario')
    VH:SendToUser("<HubSecurity> Your nickprefix is NOT correct, the allowed prefixs is: " .. prefix .. "|", 'Mario')

Remember to include the end pipe "|".

Input parameters: 1= data, 2= nick

Old method: VH:SendDataToUser

VH:SendPMToAll

This method sends a boadcast message to all users which class is between min_class and max_class (including them) with nickname as_nick. End-pipe after the data is needed. For example:

    VH:SendPMToAll("<"..BotName.."> This is an example message|", 'OpChat', 3, 10)

Input parameters: 1= message, 2= as_nick, 3= min_class, 4= max_class

VH:SendToClass

This methods will sends a MyINFO data to a users which class is between min_class and max_class (including them). End-pipe after the data is needed. For example:

    VH:SendToClass ("$OpList "..list.."|", 0, 10)
    VH:SendToClass ("<Mario>"..string.."|", 5, 10)
    VH:SendToClass ("$HubName This is my hub- And this is the topic".."|", 0, 10)

Input parameters: 1= data, 2= min_class, 3= max_class

Old method: VH:SendDataToAll

VH:ReportUser

Report a user with the given nickname with given message to the OP Chat

Input parameters: 1= nick, 2= message

VH:SendToOpChat

Send the given message in the OPChat of the hub.

Input parameters: 1= message

SQL

VH:SQLQuery

With this method you can run a query of your MySQL database:

     result, count = VH:SQLQuery ("DELETE FROM `reglist` WHERE `nick` = '".. nick .."' LIMIT 1")

The method will return the number of total rows in the count variable.

UPDATE and DELETE queries returns as count 0

Input parameters: 1= query

VH:SQLFetch

With this method you can retrieve data from selected rows with VH:SQLQuery method. Row is the number of the row. For example:

    result, rows = VH:SQLQuery ("SELECT `nick`, `class`, `reg_op` FROM `reglist` WHERE `nick` LIKE '%Mar%' ORDER BY `nick` ASC")
    if rows > 0 then
          for x = 0, rows - 1 do
          result, nick, class, reg_op = VH:SQLFetch (x)
          other code ....
    end

Note that row indexes are zero based.

Input parameters: 1= row number

VH:SQLFree

It clears memory from last query requested with VH:SQLQuery method. After this method VH:SQLFetch will always result false.

⚠️ **GitHub.com Fallback** ⚠️