Python
  Home arrow Python arrow IRC on a Higher Level Continued
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PYTHON

IRC on a Higher Level Continued
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 3
    2005-10-19


    Table of Contents:
  • IRC on a Higher Level Continued
  • More Action Methods
  • Client-To-Client Protocol
  • Sending to Another Client

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    IRC on a Higher Level Continued
    ( Page 1 of 4 )

    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.

    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
     

       

    PYTHON ARTICLES

    - 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
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek