Home arrow Python arrow Page 2 - IRC on a Higher Level Continued

More Action Methods - Python

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.

TABLE OF CONTENTS:
  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
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

In case you need to see what time it is according to the server, you can use the time method. You simply call it, passing no arguments:

...
server.time()
...

The server replies with a “391” message. By looking through the list I gave you earlier, you will find that this equates to the “time” code.

If we need to know the administrator of a certain server, we can use the admin method. It simply sends an “ADMIN” command to the server, and the server sends back the appropriate information. The admin method takes no arguments:

...
server.admin()
...

We can get more information about the server by using the “INFO” command, which is called by the corresponding method, info. Like the admin method, the info method takes no arguments:

...
server.info()
...

The message of the day may be retreived using the motd method:

...
server.motd()
...

A list of channels might prove extremely useful to your application. For example, let's say your application needed to join channels with over 20 users, or let's say that your application always needed to be in the most popular channel on the network. The list method may be used, which issues the “LIST” command to the server, and the server's response can be caught by setting handlers for the events “LISTSTART”, “LIST” and “LISTEND”:

...
server.list()
...

If you need to examine the topic of a channel, you can send a “TOPIC” command with the topic method:

...
server.topic ( '#channel' )
...

If you are a channel operator, you may also use the list method to set the topic of a given channel by passing an additional argument to the method:

...
server.topic ( '#channel', 'New Topic' )
...

Similarly, the modes of a channel may be examined by using the mode method. The method may also be used to examine user methods:

...
server.mode ( '#channel' )
server.mode ( 'User_Name' )
...

If you wish to set a mode, the same method is used along with an additional argument:

...
server.mode ( '#channel', '+m' )
...

You may want to create an application that is responsible for controlling a channel. For example, let's say you wanted to kick users who sent too many messages to the channel too quickly. The kick method is used for this:

...
server.kick ( '#channel', 'User_Name' )
...

It might also be a good idea to leave a reason for kicking the user:

...
server.kick ( '#channel, 'User_Name', 'Kicked for flooding.' )
...

If your application needs a lot of power to operate, you can log on as an IRC operator:

...
server.oper ( 'User_Name', 'password' )
...

You can also send a raw string to the server using the send_raw method. It takes one argument, which is the string you want to send:

...
server.send_raw ( 'NICK UserName2' )
...



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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PYTHON ARTICLES

- 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: