Modules/bIRC/ircRegister: Difference between revisions
(Created page with '{{ml_birc}} __NOTOC__ This function is used to register an {{ml_birc|ircbot}} for the current resource. By registering an ircbot for current resource, you are able to use the cal…') |
|||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
{{ml_birc}} | {{ml_birc}} | ||
__NOTOC__ | __NOTOC__ | ||
This function is used to register an {{ml_birc|ircbot}} for | This function is used to register an {{ml_birc|ircbot}} for specified resource. By registering an ircbot for a resource, you are able to use the callbacks called by that bot in that resource. | ||
'''Note:''' It is required to register your ircbot to the module if you're willing to use callbacks with other resources than the one where specified ircbot was originally created. This function is automatically executed for that specific resource when creating a new ircbot using {{ml_birc|ircCreateBot}} so registering a newly created ircbot within same resource is not required. | '''Note:''' It is required to register your ircbot to the module if you're willing to use callbacks with other resources than the one where specified ircbot was originally created. This function is automatically executed for that specific resource when creating a new ircbot using {{ml_birc|ircCreateBot}} so registering a newly created ircbot within same resource is not required. | ||
Line 7: | Line 7: | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool ircRegister ( ircbot theBot ) | bool ircRegister ( ircbot theBot, [ string resourceName = getResourceName ( getThisResource() ) ] ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''theBot:''' The ircbot which you want to call the callbacks | *'''theBot:''' The ircbot which you want to call the callbacks. | ||
===Optional Arguments=== | |||
{{OptionalArg}} | |||
*'''resourceName:''' The name of resource to which the ircbot should be registered. The resource specified must be running. Defaults to current resource's name. | |||
===Returns=== | ===Returns=== | ||
Line 25: | Line 29: | ||
-- ircRegister ( theBot ) is automatically executed | -- ircRegister ( theBot ) is automatically executed | ||
end | end | ||
addEventHandler ( "onResourceStart", getResourceRootElement ( | addEventHandler ( "onResourceStart", getResourceRootElement (), resourceStart ) | ||
-- This function will be called! | -- This function will be called! | ||
Line 44: | Line 48: | ||
end | end | ||
end | end | ||
addEventHandler ( "onResourceStart", getResourceRootElement ( | addEventHandler ( "onResourceStart", getResourceRootElement (), resourceStart ) | ||
-- This function wouldn't be called if ircRegister wasn't executed! | -- This function wouldn't be called if ircRegister wasn't executed! |
Latest revision as of 16:45, 11 February 2015
This function is provided by the external module Basic IRC Module. You must install this module to use this function. | |
This function is used to register an ircbot for specified resource. By registering an ircbot for a resource, you are able to use the callbacks called by that bot in that resource.
Note: It is required to register your ircbot to the module if you're willing to use callbacks with other resources than the one where specified ircbot was originally created. This function is automatically executed for that specific resource when creating a new ircbot using ircCreateBot so registering a newly created ircbot within same resource is not required.
Syntax
bool ircRegister ( ircbot theBot, [ string resourceName = getResourceName ( getThisResource() ) ] )
Required Arguments
- theBot: The ircbot which you want to call the callbacks.
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.
- resourceName: The name of resource to which the ircbot should be registered. The resource specified must be running. Defaults to current resource's name.
Returns
Returns true if registering callbacks was succesful, false otherwise.
Example
This example creates an ircbot called DummyBot on when resource ircecho starts. DummyBot is now able to call the callback function event_ircOnText inside resource ircecho.
Once resource ircecho2 starts, it checks if ircbot named DummyBot exists and if it does, it registers that bot's callbacks for resource ircecho2. Now DummyBot is able to call the callback function event_ircOnText also inside resource ircecho2.
function resourceStart() theBot = ircCreateBot ( "DummyBot" ) -- ircRegister ( theBot ) is automatically executed end addEventHandler ( "onResourceStart", getResourceRootElement (), resourceStart ) -- This function will be called! function event_ircOnText ( theBot, channel, sender, message ) if channel == ircGetName( theBot ) then outputServerLog ( "[IRC-ECHO] " .. ircGetName( theBot ) .. " received PM from " .. sender .. ": " .. message ) else outputServerLog ( "[IRC-ECHO] " .. ircGetName( theBot ) .. " received text on " .. channel .. " from " .. sender .. ": " .. message ) end end
function resourceStart() if ircGetBotByName ( "DummyBot" ) then ircRegister ( ircGetBotByName ( "DummyBot" ) ) end end addEventHandler ( "onResourceStart", getResourceRootElement (), resourceStart ) -- This function wouldn't be called if ircRegister wasn't executed! function event_ircOnText ( theBot, channel, sender, message ) if channel == ircGetName( theBot ) then outputServerLog ( "[IRC-ECHO] " .. ircGetName( theBot ) .. " received PM from " .. sender .. ": " .. message ) else outputServerLog ( "[IRC-ECHO] " .. ircGetName( theBot ) .. " received text on " .. channel .. " from " .. sender .. ": " .. message ) end end
See Also
Bot functions
Creation
Connection
Other
IRC functions
Channel
- ircGetChannelMode
- ircGetChannelTopic
- ircGetChannelUsers
- ircGetConnectedChannels
- ircJoinChannel
- ircPartChannel
- ircSetChannelMode
- ircSetChannelTopic