Python
  Home arrow Python arrow Page 3 - Basic IRC Tasks
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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? 
PYTHON

Basic IRC Tasks
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2005-04-18

    Table of Contents:
  • Basic IRC Tasks
  • Communication Tasks
  • Channel Related Tasks
  • User Related Tasks
  • Processing Information

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


    Basic IRC Tasks - Channel Related Tasks


    (Page 3 of 5 )

    The two most basic channel related tasks are joining and parting a channel. The commands are “JOIN” and “PART” and look like this:

    JOIN channel

    PART channel

    No surprises there. Let's put it into Python code:

    def join ( self, channel ):

       self.send ( 'JOIN ' + channel )

    def part ( self, channel ):

       self.send ( 'PART ' + channel )

    Getting and setting the topic is also pretty simple. The same command, “TOPIC”, is used for both operations. Here is how to get and set a topic, in the respective order:

    TOPIC channel

    TOPIC channel topic

    Our topic should not actually retrieve the data, though. Instead, the recv and retrieve methods should catch it, so creating a method to “get” and set the topic should be pretty simple.

    def topic ( self, channel, topic = '' ):

       self.send ( 'TOPIC ' + channel + ' ' + topic )

    To get a list of names of everyone in a given channel, the “NAMES” command is used:

    NAMES #channel

    The Python version is short and sweet:

    def names ( self, channel ):

       self.send ( 'NAMES ' + channel )

    IRC allows people to invite their friends to a certain channel using the “INVITE” command:

    INVITE person channel

    Let's create an invite method:

    def invite ( self, nick, channel ):

       self.send ( 'INVITE ' + nick + ' ' + channel )

    Setting a channel's mode is done with the “MODE” command:

    MODE channel mode

    Sometimes, a user must be specified:

    MODE channel user

    To make that a bit more clear, here's an example:

    MODE #python +o Peyton

    The above command would give “Peyton” operator status in a channel. Let's create a mode method:

    def mode ( self, channel, mode, nick = '' ):

       self.send ( 'MODE ' + channel + ' ' + mode + ' ' + nick )

    If you have operator status in a channel, you may kick a user from the channel:

    KICK channel user

    A reason can also be specified:

    KICK channel user reason

    Here's the Python way:

    def kick ( self, channel, nick, reason = '' ):

        self.send ( 'KICK ' + channel + ' ' + nick + ' ' + reason )

    More Python Articles
    More By Peyton McCullough


       · One thing though, your code does not take into account the IRC PING command, so your...
       · The source (...!...@...) on the beginning of the message is not mandatory. The first...
     

       

    PYTHON ARTICLES

    - 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
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT