Modules/bIRC/ircGetUserHost: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with '{{ml_birc}} __NOTOC__ This function returns the hostmask of a specified user in format user@host. The specified {{ml_birc|ircbot}} has to be in one of the channels the specified …')
 
 
Line 33: Line 33:
         -- params[1] has the string "!ban" which we don't need
         -- params[1] has the string "!ban" which we don't need
         -- params[2] has the user name
         -- params[2] has the user name
         if ircIsInChannel( theBot, channel, params[2] ) then
         if ircIsInChannel ( theBot, channel, params[2] ) then
             local userHost = ircGetUserHost( theBot, params[2] )
             local userHost = ircGetUserHost ( theBot, params[2] )
             if userHost then -- if user host was successfully received
             if userHost then -- if user host was successfully received
                 local hostMask = ircFormatHost( params[2] .. "!" .. userHost )
                 local hostMask = ircFormatHost ( params[2] .. "!" .. userHost )
                 if hostMask then -- and if formatting was successful
                 if hostMask then -- and if formatting was successful
                     ircSetChannelMode( theBot, channel, "+b " .. hostMask )
                     ircSetChannelMode ( theBot, channel, "+b " .. hostMask )
                 end
                 end
             else
             else
                 ircSendMessage( theBot, channel, "Failed to retrieve user host!" )
                 ircSendMessage ( theBot, channel, "Failed to retrieve user host!" )
             end
             end
         end
         end

Latest revision as of 14:47, 15 August 2009

Package-x-generic.png This function is provided by the external module Basic IRC Module. You must install this module to use this function.

This function returns the hostmask of a specified user in format user@host. The specified ircbot has to be in one of the channels the specified user is in.

Syntax

string ircGetUserHost ( ircbot theBot, string user )

Required Arguments

  • theBot: The ircbot which is in the channel
  • user: The user whose hostmask you want to get

Returns

Returns the host of specified user if it could be retrieved, or false if it failed or invalid arguments were passed.

Example

This example creates an ircbot called DummyBot makes it connect to a server and join a channel. It also includes an IRC command '!ban' which can be used to ban users (unable to talk or join) from IRC without kicking them from the channel.

function resourceStart ( )
    theBot = ircCreateBot ( "DummyBot" )
    ircConnect ( theBot, "irc.gtanet.com", 6667 )
end
addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource() ), resourceStart )
 
function event_ircOnConnect ( theBot )
    setTimer ( ircJoinChannel, 2000, 1, theBot, "#testchannel" )
end

function event_ircOnText ( theBot, channel, sender, message )
    if message:find( "!ban" ) then
        local params = split ( message, string.byte (' ') )
        -- params[1] has the string "!ban" which we don't need
        -- params[2] has the user name
        if ircIsInChannel ( theBot, channel, params[2] ) then
            local userHost = ircGetUserHost ( theBot, params[2] )
            if userHost then -- if user host was successfully received
                local hostMask = ircFormatHost ( params[2] .. "!" .. userHost )
                if hostMask then -- and if formatting was successful
                    ircSetChannelMode ( theBot, channel, "+b " .. hostMask )
                end
            else
                ircSendMessage ( theBot, channel, "Failed to retrieve user host!" )
            end
        end
    end
end

See Also

Bot functions

Creation

Connection

Other

IRC functions

Channel

User

Communication

Other