Thread: Beginners Programming Challenge #21
beginners programming challenge #21
the challenge
create automated rfc-2812 client... more commonly known irc bot.
overview
challenge exercise in client-server communications , reading standards document. using protocal defined in rfc 2812 objective create client (a bot) responds messages sent out server. example, create simple bot greets people enter channel, or complicated bot generates somewhat-coherent phrases using markov chains , machine learning. whether simple or complicated, irc bots need able connect server, set nick, , join channel. non-passworded servers, simple sending nick followed join once connection server has been opened.
purposes of contest, have bot hang out on #ufpc channel on chat.freenode.net server. should see either me (queue29) or bot (cbot) once connect (and maybe few other challengers well).
howdoidoit
intermediate , advanced programmers: don't read this, read rfc 2812. contains need know. section beginners maybe have never opened connection or heard of internet chat relay. instead of having guys scour 'net old sample code conforms old standard, including working template demonstrates fundamentals of protocal:
code:# original source: http://www.osix.net/modules/article/?id=780 # (updated new standard) import sys import socket import string import time host='chat.freenode.net' port=6667 nick='reallysimplebot' ident='nobody' rname='your name' channel='#ufpc' s = socket.socket() s.connect((host, port)) s.send('nick ' + nick + '\r\n') s.send('user ' + ident + ' 0 * :' + rname + '\r\n') while true: line = s.recv(1024) print ">> " + line if 'motd command' in line: print '<< sending join...' s.send('join ' + channel + '\r\n') elif 'join' in line: print '<< sending welcome...' s.send('privmsg ' + channel + ' :welcome!\r\n') elif 'ping' in line: print'<< sending pong...' s.send('pong ' + channel + '\r\n')
what's going on? first up, open connection server using plain sockets. can think of host url of server, in our case chat.freenode.irc . port port number- non ssl, pick 1 of 6665, 6666, 6667, 8000, 8001, 8002. create connection (super easy in python!). first 2 messages send server important. designated in rfc 2812 section 3.1, first 2 messages sent server should 'nick <params>' followed 'user <params>' unless there password, in case 'pass <password>' goes first. server/channel using not password protected. important, , many of going confused this: messages sent server must end in windows style carriage returns: '\r\n' instead of usual '\n' . it's part of standard, , bot won't work if forget that!
should note messages contain 1, 2, or 3 parts, delimted (awkardly, in opinion) space characters , : characters. section 2.3.1 covers in detail, can away reading format examples in document under each command's explanation. example, in nick section, given examples:
so bot connected server, need join actual channel. first, should wait until server stops spamming messages. indication of when server sends message like: :holmes.freenode.net 376 ezbot :end of /motd command. in example bot, when variable line contains "motd command", sends join command. join command "join #ufpc \r\n" .code:nick wiz ; introducing new nick "wiz" if session still unregistered, or user changing nickname "wiz" :wiz!jto@tolsun.oulu.fi nick kilroy ; server telling wiz changed nickname kilroy.
lastly in example bot mechanism letting server know bot still alive. every once in while, server send ping message (section 3.7.2) , must send pong message in response. if don't, server disconnect you.
extra credit
- have bot connect using ssl: chat.freenode.net ssl ports include 6697, 7000, , 7070.
- creative! there many things can bot do, make yours useful , interesting things
- have bot send messages in color
help
first, try read , understand rfc 2812. 1 of goals of challenge. of course can find here, or on #ufpc! can check out source code cbot here.
judging
judging based on design: project great because there _tons_ of room modularizing code. giant python scripts no classes , functions make me sad. don't want me sad, you? usefulness , creativity factors. there numerous 'sample' bots kind of work don't much. should make bot stand out doing purposeful things like.. replying weather reports, detecting floods, keeping track of karma, , whatever else can think of.
have fun! judging commence in few weeks, or when entries stop coming in.
interesting challenge; ensure testing of bots done in private channels.
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk Beginners Programming Challenge #21
Ubuntu
Comments
Post a Comment