kibot.m_irclib
index
/usr/src/rpm/BUILD/kibot-0.0.12/kibot/m_irclib.py

 
Modules
       
bisect
errno
kibot.irclib
kibot
os
select
socket
string
sys
time
traceback
types

 
Classes
       
kibot.irclib.Connection
DirectConnection
DirectConnectionMaster
exceptions.Exception
StopHandlingEvent
kibot.irclib.IRC
IRC
kibot.irclib.ServerConnection(kibot.irclib.Connection)
ServerConnection
__builtin__.object
Event
Timer

 
class DirectConnection(kibot.irclib.Connection)
     Methods defined here:
__init__(self, irclibob, sock, conn_id)
close(self)
connect(self)
process_data(self)
write(self, data)

Methods inherited from kibot.irclib.Connection:
execute_at(self, at, function, arguments=())
execute_delayed(self, delay, function, arguments=())

 
class DirectConnectionMaster(kibot.irclib.Connection)
    Listens for connections on a socket, and then feeds them
directly to the bot.  You need one Master, which then creates a
DirectConnection instance for each incoming connection.
 
  Methods defined here:
__del__(self)
__init__(self, irclibob, listen)
close(self)
connect(self)
process_data(self)
called when the master socket is readable, which means that
someone is connecting to it

Methods inherited from kibot.irclib.Connection:
execute_at(self, at, function, arguments=())
execute_delayed(self, delay, function, arguments=())

 
class Event(__builtin__.object)
    Event instances are used to represent irc events, and are what
handlers receive.  Event objects are read-only, and have a number
of standard attributes:
  type    - event type, this is first arg to bot.set_handler(...)
  source  - event source, usually a nickmask or server name
  target  - event target, usually a channel or nick
  args    - list containing arguments
  raw     - the raw event, usually the full irc string
  flags   - a dict that can be used by event generators for
            arbitrary information (this is optional)
 
Here's an example.  If the bot is on channel #mtest, and someone
(lets say michael) types "hello" into the channel, the corresponding
Event instance will have the following attributes:
 
  type:   'pubmsg'
  source: 'michael!~mstenner@alai.adsl.duke.edu'
  target: '#mtest'
  args:   ['hello']
  raw:    ':michael!~mstenner@alai.adsl.duke.edu PRIVMSG #mtest :hello'
 
Note that the exact handling of each type of event depends on the irc
protocol and also on the event type.  Kibot generates some
"secondary" events internally.  For example, the 'command' Event
instance looks like this:
 
  type:   'command'
  source: 'michael'   <- nick who executed the command
  target: 'path'      <- command as typed
  args:   ['']        <- args to the command (as a single string)
  raw     < the kibot.CommandHandler.Command instance >
 
If you're having trouble figuring out how handle and deal with an event
be sure to turn up logging (to at least level 5) and look at the events
as they ocme in.
 
  Methods defined here:
__init__(self, type, source, target, args, raw='', conn=None, flags=None)
__str__(self)

Properties defined here:
args
get = _get_args(self)
conn
get = _get_conn(self)
flags
get = _get_flags(self)
raw
get = _get_raw(self)
source
get = _get_source(self)
target
get = _get_target(self)
type
get = _get_type(self)

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Event' objects>
list of weak references to the object (if defined)

 
class IRC(kibot.irclib.IRC)
     Methods defined here:
add_timer(self, timer)
del_timer(self, timer)
process_once(self, timeout=0)
process_timeout(self)
server(self)
Creates and returns a ServerConnection object.

Methods inherited from kibot.irclib.IRC:
__init__(self, fn_to_add_socket=None, fn_to_remove_socket=None, fn_to_add_timeout=None)
Constructor for IRC objects.
 
Optional arguments are fn_to_add_socket, fn_to_remove_socket
and fn_to_add_timeout.  The first two specify functions that
will be called with a socket object as argument when the IRC
object wants to be notified (or stop being notified) of data
coming on a new socket.  When new data arrives, the method
process_data should be called.  Similarly, fn_to_add_timeout
is called with a number of seconds (a floating point number)
as first argument when the IRC object wants to receive a
notification (by calling the process_timeout method).  So, if
e.g. the argument is 42.17, the object wants the
process_timeout method to be called after 42 seconds and 170
milliseconds.
 
The three arguments mainly exist to be able to use an external
main loop (for example Tkinter's or PyGTK's main app loop)
instead of calling the process_forever method.
 
An alternative is to just call ServerConnection.process_once()
once in a while.
add_global_handler(self, event, handler, priority=0)
Adds a global handler function for a specific event type.
 
Arguments:
 
    event -- Event type (a string).  Check the values of the
    numeric_events dictionary in irclib.py for possible event
    types.
 
    handler -- Callback function.
 
    priority -- A number (the lower number, the higher priority).
 
The handler function is called whenever the specified event is
triggered in any of the connections.  See documentation for
the Event class.
 
The handler functions are called in priority order (lowest
number is highest priority).  If a handler function returns
"NO MORE", no more handlers will be called.
disconnect_all(self, message='')
Disconnects all connections.
execute_at(self, at, function, arguments=())
Execute a function at a specified time.
 
Arguments:
 
    at -- Execute at this time (standard "time_t" time).
 
    function -- Function to call.
 
    arguments -- Arguments to give the function.
execute_delayed(self, delay, function, arguments=())
Execute a function after a specified time.
 
Arguments:
 
    delay -- How many seconds to wait.
 
    function -- Function to call.
 
    arguments -- Arguments to give the function.
process_data(self, sockets)
Called when there is more data to read on connection sockets.
 
Arguments:
 
    sockets -- A list of socket objects.
 
See documentation for IRC.__init__.
process_forever(self, timeout=0.20000000000000001)
Run an infinite loop, processing data from connections.
 
This method repeatedly calls process_once.
 
Arguments:
 
    timeout -- Parameter to pass to process_once.
remove_global_handler(self, event, handler)
Removes a global handler function.
 
Arguments:
 
    event -- Event type (a string).
 
    handler -- Callback function.
 
Returns 1 on success, otherwise 0.

 
class ServerConnection(kibot.irclib.ServerConnection)
    
Method resolution order:
ServerConnection
kibot.irclib.ServerConnection
kibot.irclib.Connection

Methods defined here:
__init__(self, irclibobj)
action(self, target, action)
###################################################################
admin(self, server='')
connect(self, server, port, nickname, password=None, username=None, ircname=None, log_in=1)
Connect/reconnect to a server.
 
Arguments:
    server   -- Server name.
    port     -- Port number.
    nickname -- The nickname.
    password -- Password (if any).
    username -- The username.
    ircname  -- The IRC name.
 
This function can be called to reconnect a closed connection.
 
Returns the ServerConnection object.
ctcp(self, ctcptype, target, parameter='')
ctcp_reply(self, target, parameter)
disconnect(self, message='')
Hang up the connection.
 
Arguments:
 
    message -- Quit message.
globops(self, text)
info(self, server='')
invite(self, nick, channel)
ison(self, nicks)
Send an ISON command.
nicks is a list of nicks
join(self, channel, key='')
kick(self, channel, nick, comment='')
links(self, remote_server='', server_mask='')
list(self, channels=None, server='')
log_in(self)
lusers(self, server='')
mode(self, target, command)
motd(self, server='')
names(self, channels=None)
nick(self, newnick)
notice(self, target, text)
oper(self, nick, password)
part(self, channels)
pass_(self, password)
ping(self, target, target2='')
pong(self, target, target2='')
privmsg(self, target, text)
privmsg_many(self, targets, text)
process_data(self)
[Internal]
quit(self, message='')
sconnect(self, target, port='', server='')
send_raw(self, string)
Send raw string to the server.
This is a convenience function for sending a send_raw event
squit(self, server, comment='')
stats(self, statstype, server='')
time(self, server='')
topic(self, channel, new_topic='')
trace(self, target='')
user(self, username, localhost, server, ircname)
userhost(self, nicks)
users(self, server='')
version(self, server='')
wallops(self, text)
who(self, target='', op='')
whois(self, targets)
whowas(self, nick, max='', server='')

Methods inherited from kibot.irclib.ServerConnection:
add_global_handler(self, *args)
Add global handler.
 
See documentation for IRC.add_global_handler.
close(self)
Close the connection.
 
This method closes the connection permanently; after it has
been called, the object is unusable.
get_nickname(self)
Get the (real) nick name.
 
This method returns the (real) nickname.  The library keeps
track of nick changes, so it might not be the nick name that
was passed to the connect() method.
get_server_name(self)
Get the (real) server name.
 
This method returns the (real) server name, or, more
specifically, what the server calls itself.
is_connected(self)
Return connection status.
 
Returns true if connected, otherwise false.

Methods inherited from kibot.irclib.Connection:
execute_at(self, at, function, arguments=())
execute_delayed(self, delay, function, arguments=())

 
class StopHandlingEvent(exceptions.Exception)
     Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
class Timer(__builtin__.object)
    Timer is the class used to create delayed and/or repeating functions.
 
Timer instance should be created and handed off to bot.set_timer().
You should keep a reference around so you can remove it, though.
 
Repeating functions should return 0 to be removed or 1 to continue.
Returning otherwise will result in an exception and somewhat undefined
behavior.
 
  Methods defined here:
__cmp__(self, other)
__init__(self, seconds, func, args=(), kwargs={}, fromnow=1, repeat=None)
seconds   - when the function should be called (the first time)
func      - python function to call
args      - arguments to pass to the function
kwargs    - keyword arguments to pass to the function
fromnow   - if 1, seconds is interpreted as number of seconds
            from the time if instantiation.  If zero, it's an
            absolute unix time (number of seconds since Jan 1, 1970)
repeat    - if None, function will only be called once, and will
            be automatically removed.  If an integer, repeat at
            that interval (in seconds)
run(self)
Internal method

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Timer' objects>
list of weak references to the object (if defined)

 
Functions
       
cprefix(thing, prefix)

 
Data
        all_events = ['disconnect', 'ctcp', 'ctcpreply', 'error', 'join', 'kick', 'mode', 'part', 'ping', 'privmsg', 'privnotice', 'pubmsg', 'pubnotice', 'quit', 'statskline', 'statsqline', 'statsnline', 'statsiline', 'statscommands', 'statscline', ...]
generated_events = ['disconnect', 'ctcp', 'ctcpreply']
log = <kibot.logger.Logger instance>
numeric_events = {'001': 'welcome', '002': 'yourhost', '003': 'created', '004': 'myinfo', '005': 'featurelist', '200': 'tracelink', '201': 'traceconnecting', '202': 'tracehandshake', '203': 'traceunknown', '204': 'traceoperator', ...}
protocol_events = ['error', 'join', 'kick', 'mode', 'part', 'ping', 'privmsg', 'privnotice', 'pubmsg', 'pubnotice', 'quit']