Creating bots

From Xertion Wiki
Jump to: navigation, search

About bots

Bots are a useful way to create services to run on top of a simpler protocol, like IRC. Bots are created as call/response computer programs and can wait on an IRC for users to request a service, or they can be built to intermittently interact with users.


Misuse of bots on Xertion will likely result in IP bans from unhappy admins. Don't do anything on the Xertion network that you wouldn't reasonably do on yours without direct access to the hardware. This means thoroughly testing your bot before releasing it into main channels.

Basics of bot creation

A bot needs to be able to do the following, at minimum.

  • Recognize the server
  • PONG when PING'ed.
  • Authenticate to NickServ
  • Send PRIVMSG messages to the channel
  • Handle incoming messages

Most languages, such as C and Java, are perfectly capable of fulfilling these requirements. Choosing a language is dependent on the programmer's preferences.

PONG when PING'ed

Basic knowledge about the IRC protocol and PING/PONG is assumed.

This is the most basic part of all of writing bots. The IRC server will send a PING message in regular intervals, to which the client must respond. You must be ready to PING during registration (sending NICK and USER commands) already in your code since some servers/networks send a so-called ping cookie to stop certain primitive drones. You can safely just echo whatever the server sent to you.

Example of a ping cookie (inbound messages from the server begin with "<< ", outgoing messages begin with ">> " here. This is solely for illustration and not part of the actual client-to-server protocol):

<< PING :nXUmTd}T{G
>> PONG :nXUmTd}T{G

Regular ping (note that you cannot rely on whatever info is being sent in PING for the network you're on. Every IRCd seems to send different information):


Your bot should keep track of the server's last ping, too, and handle ping timeouts as well. Especially if your bot is running from a connection that randomly reassigns dynamic IPs, your address may simply change and your bot will happily wait for input from the IRC server, which will never come. Thus, implementing a ping check (Don't bother pinging the server yourself though, a timeout check based on last PING occasionally is plenty) will allow you to mitigate such issues.