Changes between Version 16 and Version 17 of PyBc/PythonBots
- Timestamp:
- 01/09/10 21:22:23 (8 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
PyBc/PythonBots
v16 v17 167 167 == Creating an IRC Bot == 168 168 169 The first thing any IRC bot needs to do is connect 169 Before we get started, let's go over a brief summary of how IRC works for those who don't know. IRC ("internet relay chat") is a protocol designed to let groups of users chat in individual rooms ("channels") on one or more networks. Most networks have several servers to minimize the load, and the servers stay in constant communication to allow users from one server on a network to talk to users on other servers on that network. There are hundreds of IRC networks available on the internet, each with thousands of channels. The actual protocol is pretty simple, and we could probably implement an IRC bot in Python just using network sockets, but why reinvent the wheel? 170 171 === Getting Started === 172 173 The first thing any IRC bot needs to do is connect to a server and (usually) join a channel. Using {{{python-irclib}}}, this is a simple matter. 170 174 171 175 {{{ … … 200 204 201 205 == Replying to Messages == 206 207 In order to make our IRC bot useful, we need to make it respond to messages from other users. We're going to make our bot respond to messages in channels that begin with "!pig". When our bot sees a message like that, it will look at the text after the "!pig" and translate it into Pig Latin and send it back to the user. To eliminate confusion, we'll also figure out the username of the person who sent the command and prefix our reply with that name. 202 208 203 209 {{{
![(please configure the [header_logo] section in trac.ini)](/cgi-bin/hackerwithin.fcgi/chrome/site/thwlogo-small.png)