Bot
com.axlogic.magik.irc


com.tekadence.core.Base
  |
  +--com.axlogic.magik.irc.Bot

The Bot object provides basic IRC client/bot services to Tekadence Magik.

Adding a Bot object to a project will allow the application to connect to an IRC server and send and receive standard messages and events. By adding more than one instance of the Bot object to your application you can connect to multiple servers, or have multiple connections a single server.

Version:

1.0

 
Author:

Jared Kaplan, http://www.axlogic.com

Property Summary
Boolean
connected
  Read only property that gets set when the Bot connects/disconnects from the server.
Boolean
enabled
  Enables or disables the Bot.
Boolean
enableLogging
  Enables logging of IRC messages to the console window.
String
nick
  The nickname given to the bot instance when it connects to the server.
String
port
  Port number of the server.
String
server
  IRC server that the bot connects to.

Message Summary
void
disconnect()
  Disconnects from the server.
StringArray
getChannelList()
  Returns a StringArray of all the channels the bot is in.
getUserList( String channel )
  Returns a UserList of all the users in a specific channel.
void
join( String channel )
  Joins a channel.
void
kick( String channel, String nick, String reason )
  Kicks a user off a specific channel, giving a reason.
void
leave( String channel )
  Leaves a channel.
void
reconnect()
  Reconnects to the server.
void
sendAction( String action, String target )
  Sends an action to the specified target.
void
sendCTCPRequest( String target, String request, String data )
  Sends a CTCP command to the specified target.
void
sendInvite( String channel, String nick )
  Invites a user to join a specific channel.
void
sendMessage( String messageText, String target )
  Sends a message to the specified target.
void
sendNotice( String notice, String target )
  Sends a notice to the specified target.
void
sendRawLine( String line )
  Send a raw line of text to to the server.
void
setOp( String nick, String channel, Boolean op )
  Grants or removes operator privilidges to a user on a specific channel.
void
setTopic( String channel, String topic )
  Sets the current topic for a channel.
void
setVoice( String nick, String channel, Boolean voice )
  Grants or removes voice privilidges to a user on a specific channel.

Event Summary
void
receiveAction( String sender, String login, String hostname, String target, String action )
  This message is called when an ACTION is sent from a user.
void
receiveConnect()
  This message is called when the bot connects to the server.
void
receiveCTCPRequest( String sender, String login, String hostname, String target, String request, String data )
  This message is called when CTCP request is sent to the bot.
void
receiveDisconnect()
  This message is called when the bot disconnects from the server.
void
receiveJoin( String channel, String sender, String login, String hostname )
  This message is called when a user (including us) joins a channel.
void
receiveLeave( String channel, String sender, String login, String hostname )
  This message is called when a user (including us) leaves a channel.
void
receiveLogMessage( String line )
  This message is called when the Bot generates a log message.
void
receiveMessage( String channel, String sender, String login, String hostname, String messageText )
  This message is called when a message is sent to a channel (not including messages sent by us).
void
receiveNickChange( String oldNick, String login, String hostname, String newNick )
  This message is called when a user (including us) changes their nick.
void
receiveNotice( String channel, String sender, String login, String hostname, String notice )
  This message is called when we recieve a notice.
void
receiveOpChange( String channel, String sourceNice, String sourcLogin, String sourceHostname, String target, Boolean op )
  This message is called when we recieve an op change event for a user.
void
receivePrivateMessage( String sender, String login, String hostname, String messageText )
  This message is called when a private message is sent to us.
void
receiveServerPing( String response )
  This message is called when we receive a PING request from the server.
void
receiveServerResponse( Integer code, String response )
  This message is called when we recieve a numeric server response.
void
receiveUserList( String channel, UserList users )
  This message is called when we recieve a user list from the server shortly after joining a channel.
void
receiveVoiceChange( String channel, String sourceNice, String sourcLogin, String sourceHostname, String target, Boolean voice )
  This message is called when we recieve a voice change event for a user.

DataType Detail

UserList

The UserList data type is a complex data structure that contains a list of child nodes that represent a single user (usually in a specific channel). The UserList data structure contains the following nodes for each user:

  nick - the nick of the user
prefix - the users status in the channel
voice - is true if the user is an voice priviledges in the channel
op - is true if the user has operator priviledges in the channel

Items in the UserList data structure are accessed the same way you access items in an array, and its data members the same as accessing a property on an object. The number of items in the UserList can be accessed using the size() function. For example:

 

// get the user list for a channel called #magik_bot
var userList = getUserList( "#magik_bot" );

// for each user in the user list output its data to the console
for( var i = 0; i < userList.size(); i++ ) {

    debugStr( "Nick=" + userList[i].nick );
    debugStr( "Prefix=" + userList[i].prefix );
    debugStr( "Voice=" + userList[i].voice );
    debugStr( "Op=" + userList[i].op );
}

// output xml representation of the data to the console
debugStr( userList );


Property Detail

connected
User Level: Novice, read-only

Boolean connected

  Set to true when the Bot is connected to the server.
   

enabled
User Level: Novice

Boolean enabled

  Set to true when the Bot is enabled. Normally when the application enters runtime mode the Bot will automatically log into the server. If enabled is set to false however, no action will be taken. If the enabled property is set to false while the Bot is already connected to the server, the Bot will immediately disconnect from the server.
   

enableLogging
User Level: Novice

Boolean enableLogging

  If this property is set to true, log messages generated by the Bot will be output in the console window.
   

nick
User Level: Novice

String nick

  The nickname given to the bot instance when it connects to the server. If this property is modified while the Bot is already connected to the server, it will attempt to change the Bot's current nickname.
   

port
User Level: Novice

Integer port

  Port number of the server. The default value for this property is 6667, however not all IRC servers use this port number. Before attempting to connect to a server it is a good idea to make sure you set this property to the correct value.
   

server
User Level: Novice

String server

 

The IRC server that the bot connects to.

This property is empty by default. There are many IRC servers that allow bots, and you probably want to use the server that you normally connect to when using your favorite IRC client application.

Some popular IRC servers are:

Homelan (irc.homelan.com)
FunNet (irc.funnet.org)
Chatster (irc.chatster.org)
GamesNET (west.gamesnet.net)

In order to connect to one of the servers above, you would have to set the server property to its corresponding internet address. For example, to log into the Homelan server set the property value to: irc.homelan.com.

Not all servers allow bots or multiple instances, so it is important to check the rules of the specific server you wish to connect to. Failing to abide by the rules set forth by server administrators can lead to permanent banning on that server.

   

Message Detail

disconnect

void disconnect()

 

Disconnects from the server. Providing that the Bot was connected to the server, the receiveDisconnect event will be called as soon as the disconnection is made.

To re-establish a connection with the server once the Bot has been disconnected, you should call the reconnect message.

See also:
  reconnect(), receiveDisconnect()
   

getChannelList

StringArray getChannelList()

 

Returns a StringArray of all the channels the bot is in. To access the the StringArray reference the value as a standard Tekadence Magik array data type.

Example:
This example shows how you can call the getChannelList message and iterate through the list of channels passed back in the return value. Assume that the example is a script that is part of the Bot object we are calling.

var channelList = getChannelList();

for( var i = 0; i < channelList.size(); i++ ) {
    debugStr( channelList[i] ); // do something here with the channel
}

   

getUserList

UserList getUserList( String Channel )

 

Returns a UserList of all the users in a specific channel. The Bot must be a member of the channel which is being queried in order to return the list of its users.

Example:
This example shows how you can call the getUserList message and iterate through the list of users passed back in the return value. Assume that the example is a script that is part of the Bot object we are calling.

var userList = getUserList( "#magik_bot" );

for( var i = 0; i < userList.size(); i++ ) {
    debugStr( userList[i] ); // do something here with the user
    debugStr( "Nick: " + userList[i].nick );
    debugStr( "Has Op: " + userList[i].op );
    debugStr( "Has Voice: " + userList[i].voice );
}

Parameters:
  channel - the name of the channel for which we are trying to retrieve a user list.

Returns:
  The list of users of the specified channel as UserList datatype. If the Bot is a memeber of the channel there should always be one entry in the user list, otherwise the result will be an empty user list.

See also:
  UserList
   

join

void join( String channel )

 

Joins a channel. If the Bot successfully joins the channel an immediate recieveJoin event will be sent.

Parameters:
  channel - the name of the channel that we are trying to join.

See also:
  leave(), receiveJoin()
   

kick

void kick( String channel, String nick, String reason )

 

Kicks a user off a specific channel, giving a reason. This message will only suceede if the Bot has operator privileges in the channel.

Parameters:
  channel - the name of the channel to kick the user from.
nick - the nick of the user to kick.
reason - the reason given to the user for being kicked off the channel.
   

leave

void leave( String channel )

 

Leaves a channel. If the Bot successfully leaves the channel an immediate recieveLeave event will be sent.

Parameters:
  channel - the name of the channel that we are trying to leave.

See also:
  join(), receiveLeave()
   

reconnect

void reconnect()

 

Reconnects to the server. Providing that the Bot was previously connected to a server, the receiveConnect event will be called as soon as the connection is made.

To disconnect from the server once the Bot has been connected, you should call the disconnect message.

See also:
  disconnect(), receiveConnect()
   

sendAction

void sendAction( String action, String target )

 

Sends an action to the target channel or user. An action is equivalent to using the "/me" command on most IRC servers.

Parameters:
  action - the action to send.
target - the name of the channel or user to send the action to.

See also:
  receiveAction()
   

sendCTCPRequest

void sendCTCPCommand( String target, String request, String data )

 

Sends a CTCP (Client To Client Protocol) command to the target channel or user. CTCP commands include: "PING", "FINGER", and "VERSION", and their results will vary depending on the target client software.

Parameters:
  target - the name of the channel or user to send the command to.
request - the CTCP request to send.
data - any data that is to be passed along with the CTCP request.
   
  See also:
 
  receiveCTCPRequest()
   

sendInvite

void sendInvite( String channel, String nick )

 

Invites a user to join a channel. This is necessary for channels that are specified as "invite only".

Parameters:
  channel - the channel that the user is being invited to.
nick - the nick of the user to invite.
   

sendMessage

void sendMessage( String messageText, String target )

 

Sends a message to the target channel or user.

Example:
This example shows how you can call sendMessage to send a message to both an entire channel, and as a private message to a specific user. Assume that the example is a script that is part of the Bot object we are calling.

// sends a message to the channel #magik_bot
sendMessage( "Hello there channel!", "#magik_bot" );

// sends a message to the user FrizzleFried
sendMessage( "Hi Frizz, you are the only one who can see this.", "FrizzleFried" );

Parameters:
  messageText - the message to send.
target - the name of the channel or user to send the message to.
   

sendNotice

void sendNotice( String notice, String target )

 

Sends a notice to the target channel or user.

Parameters:
  notice - the notice to send.
target - the name of the channel or user to send the notice to.
   

sendRawLine

void sendRawLine( String line )

 

Send a raw line of text to to the server. This is useful if you wish to bypass the built-in messages in the Bot to execute a command on the server, or if the Bot does not have a message that maps to a specific command.

Parameters:
  line - the line of text to send to the server.
   

setOp

void setOp( String nick, String channel, Boolean op )

 

Grants or removes operator privilidges to a user on a specific channel. The Bot must itself have operator privildges on the channel for which it is attempting to set a users operator mode.

Parameters:
  nick - the nick of the user to set operator privilidges on.
channel
- the name of the channel to set operator privilidges for.
op - if true then the user is granted operator privilidges.
   

setTopic

void setTopic( String channel, String topic )

 

Sets the current topic for a channel. The channel may require the Bot to have operator privilidges for the channel it is trying to change, if the topic is protected.

Parameters:
  channel - the channel for which the topic is to be changed.
topic - the new topic.
   

setVoice

void setVoice( String nick, String channel, Boolean voice )

 

Grants or removes voice privilidges to a user on a specific channel. The Bot must have operator privildges on the channel for which it is attempting to set a users voice mode.

Parameters:
  nick - the nick of the user to set voice privilidges on.
channel
- the name of the channel to set voice privilidges for.
voice - if true then the user is granted voice privilidges.
   

Event Detail
receiveAction

void receiveAction( String sender, String login, String hostname, String target, String action )

 

This message is called when an ACTION is sent from a user.

Parameters:
  sender - the user nick who sent the action.
login - the senders login.
hostname - the senders hostname.
target - the action target (either a channel or the Bot's nick).
action - the action message that is being sent.  

See also:
  sendAction()
   

receiveConnect

void receiveConnect()

 

This message is called when the bot connects to the server.

   

receiveDisconnect

void receiveDisconnect()

 

This message is called when the bot disconnects from the server.

See also:
  disconnect()
   

receiveJoin

void receiveJoin( String channel, String sender, String login, String hostname )

 

This message is called when a user (including us) joins a channel.

Parameters:
  channel - the channel that is being joined.
sender
- the user who is joining the channel.
login - the senders login.
hostname - the senders hostname. 

See also:
  join()
   

receiveLeave

void receiveLeave( String channel, String sender, String login, String hostname )

 

This message is called when a user (including us) leaves a channel.

Parameters:
  channel - the channel that is being joined.
sender
- the user who is joining the channel.
login - the senders login.
hostname - the senders hostname. 

See also:
  leave()
   

receiveLogMessage

void receiveLogMessage( String line )

 

This message is called when the Bot generates a log message.

Parameters:
  line - the line of text being added to the log.
   

receiveMessage

void receiveMessage( String channel, String sender, String login, String hostname, String messageText )

 

This message is called when a message is sent to a channel (not including messages sent by us).

Parameters:
  channel - the channel that the message was sent to.
sender
- the user who sent the message.
login - the senders login.
hostname - the senders hostname.
messageText - the message text.

See also:
  sendMessage()
   

receiveNickChange

void receiveNickChange( String oldNick, String login, String hostname, String newNick )

 

This message is called when a user (including us) changes their nick.

Parameters:
  oldNick - the channel that is being joined.
login
- the senders login.
hostname - the senders hostname.
newNick - the user who is joining the channel.
   

receiveNotice

void receiveNotice( String sender, String login, String hostname, String target, String notice )

 

This message is called when we recieve a notice.

Parameters:
  sender - the user nick who sent the notice.
login - the senders login.
hostname - the senders hostname.
target - the notice target (either a channel or the Bot's nick).
notice - the notice that is being sent.  

See also:
  sendNotice()
   

receivePrivateMessage

void receivePrivateMessage( String sender, String login, String hostname, String messageText )

 

This message is called when a private message is sent to the Bot.

Parameters:
  sender - the user who sent the preivate message.
login - the senders login.
hostname - the senders hostname.
messageText - the private message text.
   

receiveServerPing

void receiveServerPing( String response )

 

This message is called when we receive a PING request from the server.

Parameters:
  response - the response that gets sent back to the server.
   

receiveServerResponse

void receiveServerResponse( Integer code, String response )

 

This message is called when we recieve a numeric server response.

Parameters:
  code - the numerical code representing the server message.
response - the verbose server message.
   

receiveUserList

void receiveUserList( String channel, UserList users )

 

This message is called when we recieve a user list from the server shortly after joining a channel.

Parameters:
  channel - the channel name.
users - the user list for the channel being joined.