#Description
It's 2015 and we've all moved on from IRC, right? Wrong! Freenode (the largest FOSS focused IRC network) has over 80,000 users, and gains around 5000 new users every year. /r/DailyProgrammer, as awesome as it is, happens to have its very own IRC channel on freenode (#reddit-dailyprogrammer), but it's missing one thing: Bots.
The goal of this channel is to create an interactive IRC bot capable of performing one or more basic bot-like things.
#Formal Inputs & Outputs
##Input description
For input, the bot will be given a domain, port, nickname, and channel to join in the format:
domain:port
nickname
channel
Incoming chat messages from the server will be in the format :Nick!User@Host PRIVMSG channel :message
. That is, a command PRIVMSG
from Nick!User@Host
to the channel channel
, with the message message
.
For this challenge, you will be expected to join chat.freenode.net:6667
on
channel #rdp
with a nickname of your choosing (no spaces!).
##Output description
The first thing you should send over the connection are, the PASS, NICK, and USER messages. Since the bot isn't a registered user, you can skip the PASS message. In the USER message, only the username and and realname parameters are useful, and the rest can be random characters (commonly a single asterisk and a 0). Following that, what you first send should look like this:
NICK MyBot
USER MyBot 0 * :MyBot
After connecting, the bot should join the specified channel , where it will idle until triggered by saying it's name followed by a colon and optional whitespace. The content of the message triggering the bot will consist of a command followed by one or more whitespace characters, then a parameter for the command.
For example, on a bot with a search function YourBot: search the front page of the internet
when said in the channel would cause the bot to search online
for the query The front page of the internet
. In reply to this message, the
bot would hopefully respond https://www.reddit.com/ - reddit: the front page of the internet
.
Outgoing chat messages should be in the format PRIVMSG channel :message
.
#Notes/Hints
The RFC for the IRC cleint protocol: http://tools.ietf.org/html/rfc2812
IRC primer: http://blog.initprogram.com/2010/10/14/a-quick-basic-primer-on-the-irc-protocol/
Section 2.3.1 explains the format of all IRC messages, which is important to be familiar with when implementing the protocol. After every command is a CRLF newline, so don't forget to send that. The same holds true for incoming messages, so make sure to wait for the CRLF before attempting to parse.
Before attempting to join a channel (with the JOIN
command), you should wait
for the end of the MOTD. The end of the MOTD on freenode will appear similar
to :tepper.freenode.net 376 YourBot :End of /MOTD command.
. The important
part of that is the 376
, which is known as the RPL_ENDOFMOTD
command. Some
networks will send 422
instead, which is known as ERR_NOMOTD
.
Don't forget to respond to PING
messages, as described in section 4.6.2. You
will occasionally receive these from freenode in the format PING :message
.
You should respond to these with PONG :message
, where the message is the
same as what you received in the PING.
#Bonus
Build a rudimentary GUI for your IRC bot. This will allow for simple client functionality, such as seeing and sending messages.