Home arrow Python arrow IRC on a Higher Level Continued

IRC on a Higher Level Continued

In the last article, you were taught about events in Python-IRCLib. You were taught what some common events are, how to catch them and how to properly respond to them. While a grasp of events is crucial to developing applications that interact through IRC, it's important to realize that Python-IRCLib doesn't just deal with responding to events. The library is a few dozen kilobytes, and all of that space obviously does not contain code that deals with events. The library contains many more features, and we'll take a look at some of them in this article.

  1. IRC on a Higher Level Continued
  2. More Action Methods
  3. Client-To-Client Protocol
  4. Sending to Another Client
By: Peyton McCullough
Rating: starstarstarstarstar / 3
October 19, 2005

print this article



Action Methods

Recall the code to private message a channel or user:

server.privmsg ( '#channel', 'Message to #channel.' )
server.privmsg ( 'UserName', 'Message to UserName' )

The library contains more methods similar to the privmsg method, and a simple method is much easier to use than tinkering with the protocol itself. One such method is an extension of the privmsg method – privmsg_many. While privmsg handles a single target, privmsg_many can easily handle multiple targets. Here's how it works:

targets = [ '#channel1', '#channel2', 'UserA', 'UserB' ]
server.privmsg_many ( targets, 'This is a test message.' )

When you connect to a network, Python-IRCLib will automatically provide the server with a nickname. However, you may wish to change the nickname assigned to your application based on events or the status of your application. This is done with the nick method, which takes a single string as an argument:

server.nick ( 'New_Name' )

It may be necessary for your application to acquire information about the network it is operating on. Several methods are availible that send out the proper signal. However, keep in mind that you will need to set up the proper handlers to catch the server's response. If you've read the previous article thorougly, then this shouldn't be too much of a challenge. Let's catch one event, though, just to refresh your memory. The who method sends out a “WHO” command like this:

def handleWho ( connection, event ):

   print ' '.join ( event.arguments() )
irc.add_global_handler ( 'whoreply', handleWho )
irc.add_global_handler ( 'endofwho', handleWho )
server.who ( 'User_Name' )

More specific information about a user can be obtained using the whois method. Again, it takes a single argument:

server.whois ( 'User_Name' )

Again, the server sends a response that must be caught. In the last article, I presented a list of all supported events. Go ahead and search through the list for the appropriate event codes, and create an application that catches the server's reply to the “WHOIS” command.

The last of the “who” commands is the “WHOWAS” command. It is accessed like this:

server.whowas ( 'User_Name' )

>>> More Python Articles          >>> More By Peyton McCullough

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates


Dev Shed Tutorial Topics: