annotate irclib.py @ 275:09a5bde70919 default tip master

minor fix in Participant Signed-off-by: Changaco <changaco ατ changaco δοτ net>
author Changaco <changaco ατ changaco δοτ net>
date Wed, 05 May 2010 23:36:13 +0200
parents 18c9e8b823bc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1 # Copyright (C) 1999--2002 Joel Rosdahl
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
2 #
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
3 # This library is free software; you can redistribute it and/or
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
4 # modify it under the terms of the GNU Lesser General Public
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
5 # License as published by the Free Software Foundation; either
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
6 # version 2.1 of the License, or (at your option) any later version.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
7 #
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
8 # This library is distributed in the hope that it will be useful,
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
11 # Lesser General Public License for more details.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
12 #
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
13 # You should have received a copy of the GNU Lesser General Public
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
14 # License along with this library; if not, write to the Free Software
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
16 #
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
17 # keltus <keltus@users.sourceforge.net>
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
18 #
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
19 # $Id: irclib.py,v 1.47 2008/09/25 22:00:59 keltus Exp $
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
20
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
21 """irclib -- Internet Relay Chat (IRC) protocol client library.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
22
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
23 This library is intended to encapsulate the IRC protocol at a quite
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
24 low level. It provides an event-driven IRC client framework. It has
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
25 a fairly thorough support for the basic IRC protocol, CTCP, DCC chat,
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
26 but DCC file transfers is not yet supported.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
27
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
28 In order to understand how to make an IRC client, I'm afraid you more
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
29 or less must understand the IRC specifications. They are available
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
30 here: [IRC specifications].
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
31
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
32 The main features of the IRC client framework are:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
33
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
34 * Abstraction of the IRC protocol.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
35 * Handles multiple simultaneous IRC server connections.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
36 * Handles server PONGing transparently.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
37 * Messages to the IRC server are done by calling methods on an IRC
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
38 connection object.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
39 * Messages from an IRC server triggers events, which can be caught
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
40 by event handlers.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
41 * Reading from and writing to IRC server sockets are normally done
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
42 by an internal select() loop, but the select()ing may be done by
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
43 an external main loop.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
44 * Functions can be registered to execute at specified times by the
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
45 event-loop.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
46 * Decodes CTCP tagging correctly (hopefully); I haven't seen any
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
47 other IRC client implementation that handles the CTCP
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
48 specification subtilties.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
49 * A kind of simple, single-server, object-oriented IRC client class
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
50 that dispatches events to instance methods is included.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
51
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
52 Current limitations:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
53
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
54 * The IRC protocol shines through the abstraction a bit too much.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
55 * Data is not written asynchronously to the server, i.e. the write()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
56 may block if the TCP buffers are stuffed.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
57 * There are no support for DCC file transfers.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
58 * The author haven't even read RFC 2810, 2811, 2812 and 2813.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
59 * Like most projects, documentation is lacking...
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
60
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
61 .. [IRC specifications] http://www.irchelp.org/irchelp/rfc/
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
62 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
63
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
64 import bisect
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
65 import re
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
66 import select
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
67 import socket
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
68 import string
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
69 import sys
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
70 import time
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
71 import types
24
4e1f27ea527b First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents: 23
diff changeset
72 import threading
69
0a2b9e84bbde Strip colors from IRC messages
Charly COSTE <changaco@changaco.net>
parents: 68
diff changeset
73 import traceback
115
0ae0f8836a7a split long messages when sending on IRC
Charly COSTE <changaco@changaco.net>
parents: 89
diff changeset
74 import math
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
75
180
102f895347ff added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents: 174
diff changeset
76 import say_levels
102f895347ff added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents: 174
diff changeset
77
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
78 VERSION = 0, 4, 8
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
79 DEBUG = 0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
80
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
81 # TODO
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
82 # ----
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
83 # (maybe) thread safety
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
84 # (maybe) color parser convenience functions
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
85 # documentation (including all event types)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
86 # (maybe) add awareness of different types of ircds
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
87 # send data asynchronously to the server (and DCC connections)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
88 # (maybe) automatically close unused, passive DCC connections after a while
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
89
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
90 # NOTES
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
91 # -----
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
92 # connection.quit() only sends QUIT to the server.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
93 # ERROR from the server triggers the error event and the disconnect event.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
94 # dropping of the connection triggers the disconnect event.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
95
89
94fc538cdf65 Better format stripping for IRC messages
Charly COSTE <changaco@changaco.net>
parents: 87
diff changeset
96 strip_formatting_re = re.compile('(?:\x03[0-9]*(?:,[0-9]+)?|\x02|\x1f)')
69
0a2b9e84bbde Strip colors from IRC messages
Charly COSTE <changaco@changaco.net>
parents: 68
diff changeset
97
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
98 class IRCError(Exception):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
99 """Represents an IRC exception."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
100 pass
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
101
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
102
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
103 class IRC:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
104 """Class that handles one or several IRC server connections.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
105
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
106 When an IRC object has been instantiated, it can be used to create
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
107 Connection objects that represent the IRC connections. The
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
108 responsibility of the IRC object is to provide an event-driven
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
109 framework for the connections and to keep the connections alive.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
110 It runs a select loop to poll each connection's TCP socket and
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
111 hands over the sockets with incoming data for processing by the
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
112 corresponding connection.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
113
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
114 The methods of most interest for an IRC client writer are server,
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
115 add_global_handler, remove_global_handler, execute_at,
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
116 execute_delayed, process_once and process_forever.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
117
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
118 Here is an example:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
119
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
120 irc = irclib.IRC()
125
efdc038e757a fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents: 115
diff changeset
121 server = irc.open_connection(\"irc.some.where\", 6667, \"my_nickname\")
efdc038e757a fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents: 115
diff changeset
122 server.connect()
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
123 server.privmsg(\"a_nickname\", \"Hi there!\")
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
124 irc.process_forever()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
125
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
126 This will connect to the IRC server irc.some.where on port 6667
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
127 using the nickname my_nickname and send the message \"Hi there!\"
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
128 to the nickname a_nickname.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
129 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
130
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
131 def __init__(self, fn_to_add_socket=None,
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
132 fn_to_remove_socket=None,
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
133 fn_to_add_timeout=None):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
134 """Constructor for IRC objects.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
135
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
136 Optional arguments are fn_to_add_socket, fn_to_remove_socket
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
137 and fn_to_add_timeout. The first two specify functions that
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
138 will be called with a socket object as argument when the IRC
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
139 object wants to be notified (or stop being notified) of data
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
140 coming on a new socket. When new data arrives, the method
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
141 process_data should be called. Similarly, fn_to_add_timeout
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
142 is called with a number of seconds (a floating point number)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
143 as first argument when the IRC object wants to receive a
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
144 notification (by calling the process_timeout method). So, if
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
145 e.g. the argument is 42.17, the object wants the
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
146 process_timeout method to be called after 42 seconds and 170
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
147 milliseconds.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
148
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
149 The three arguments mainly exist to be able to use an external
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
150 main loop (for example Tkinter's or PyGTK's main app loop)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
151 instead of calling the process_forever method.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
152
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
153 An alternative is to just call ServerConnection.process_once()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
154 once in a while.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
155 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
156
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
157 if fn_to_add_socket and fn_to_remove_socket:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
158 self.fn_to_add_socket = fn_to_add_socket
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
159 self.fn_to_remove_socket = fn_to_remove_socket
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
160 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
161 self.fn_to_add_socket = None
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
162 self.fn_to_remove_socket = None
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
163
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
164 self.fn_to_add_timeout = fn_to_add_timeout
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
165 self.connections = []
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
166 self.handlers = {}
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
167 self.delayed_commands = [] # list of tuples in the format (time, function, arguments)
172
64a0e9636ae6 removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents: 167
diff changeset
168 self.charsets = {'': ['utf-8']}
174
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
169 self.connection_intervals = {'': 1}
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
170 self.connection_stacks = {}
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
171
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
172 self.add_global_handler("ping", _ping_ponger, -42)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
173
174
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
174
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
175 def _connection_loop(self, server_str):
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
176 stack = self.connection_stacks[server_str]
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
177 if len(stack) > 0:
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
178 stack[0][0](*stack[0][1])
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
179 stack.pop(0)
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
180 delay = self.connection_interval(server=server_str)
180
102f895347ff added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents: 174
diff changeset
181 self.bot.error(2, 'waiting '+str(delay)+' seconds before next connection on '+server_str, debug=True)
174
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
182 self.execute_delayed(delay, self._connection_loop, (server_str,))
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
183 else:
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
184 self.connection_stacks.pop(server_str)
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
185
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
186
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
187 def connection_interval(self, server='', seconds=None):
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
188 if seconds:
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
189 self.connection_intervals[server] = seconds
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
190 return seconds
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
191 elif self.connection_intervals.has_key(server):
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
192 return self.connection_intervals[server]
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
193 else:
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
194 return self.connection_intervals['']
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
195
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
196
125
efdc038e757a fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents: 115
diff changeset
197 def get_connection(self, server, port, nickname):
efdc038e757a fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents: 115
diff changeset
198 for c in self.connections:
219
63289aa1dea7 moved "nicknametoolong" and ServerConnection.really_connected handling to irclib, renamed ServerConnection.really_connected to .logged_in
Charly COSTE <changaco@changaco.net>
parents: 218
diff changeset
199 if c.server == server and c.port == port and nickname in [c.nickname, c.real_nickname]:
125
efdc038e757a fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents: 115
diff changeset
200 return c
efdc038e757a fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents: 115
diff changeset
201 return None
efdc038e757a fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents: 115
diff changeset
202
efdc038e757a fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents: 115
diff changeset
203 def has_connection(self, server, port, nickname):
efdc038e757a fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents: 115
diff changeset
204 if self.get_connection(server, port, nickname):
efdc038e757a fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents: 115
diff changeset
205 return True
efdc038e757a fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents: 115
diff changeset
206 return False
efdc038e757a fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents: 115
diff changeset
207
174
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
208 def open_connection(self, server, port, nickname, delay=None):
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
209 """Creates or returns an existing ServerConnection object for nickname at server:port.
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
210
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
211 server -- Server name.
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
212
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
213 port -- Port number.
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
214
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
215 nickname -- The nickname."""
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
216
125
efdc038e757a fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents: 115
diff changeset
217 c = self.get_connection(server, port, nickname)
efdc038e757a fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents: 115
diff changeset
218 if c:
efdc038e757a fixed participant.changeNickname(), renamed IRC.server() to IRC.open_connection(), created IRC.get_connection() and IRC.has_connection(), removed irclib.SimpleIRCClient (we don't need it)
Charly COSTE <changaco@changaco.net>
parents: 115
diff changeset
219 return c
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
220 c = ServerConnection(self, server, port, nickname)
174
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
221 server_str = c._server_str()
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
222 if not self.connection_stacks.has_key(server_str):
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
223 self.connection_stacks[server_str] = []
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
224 delay = self.connection_interval(server=server_str, seconds=delay)
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
225 self.execute_delayed(delay, self._connection_loop, (server_str,))
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
226 self.connections.append(c)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
227 return c
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
228
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
229 def process_data(self, sockets):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
230 """Called when there is more data to read on connection sockets.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
231
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
232 Arguments:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
233
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
234 sockets -- A list of socket objects.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
235
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
236 See documentation for IRC.__init__.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
237 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
238 for s in sockets:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
239 for c in self.connections:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
240 if s == c._get_socket():
24
4e1f27ea527b First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents: 23
diff changeset
241 c.lock.acquire()
57
ebd4278e472f Some thread safety for irclib.py
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
242 if hasattr(c, 'socket'):
210
fb0cf6bf9eab (irclib) moved ServerNotConnectedError handling from IRC.process_data() to IRC.process_forever() in order to always catch it
Charly COSTE <changaco@changaco.net>
parents: 209
diff changeset
243 c.process_data()
24
4e1f27ea527b First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents: 23
diff changeset
244 c.lock.release()
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
245
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
246 def process_timeout(self):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
247 """Called when a timeout notification is due.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
248
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
249 See documentation for IRC.__init__.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
250 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
251 t = time.time()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
252 while self.delayed_commands:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
253 if t >= self.delayed_commands[0][0]:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
254 self.delayed_commands[0][1](*self.delayed_commands[0][2])
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
255 del self.delayed_commands[0]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
256 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
257 break
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
258
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
259 def process_once(self, timeout=0):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
260 """Process data from connections once.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
261
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
262 Arguments:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
263
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
264 timeout -- How long the select() call should wait if no
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
265 data is available.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
266
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
267 This method should be called periodically to check and process
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
268 incoming data, if there are any. If that seems boring, look
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
269 at the process_forever method.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
270 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
271 sockets = map(lambda x: x._get_socket(), self.connections)
146
229a59acde0f fixes in irclib, needed because ServerConnection.socket can be a string since 42d7b622776196149c9a9a05da134a85ee9509c6
Charly COSTE <changaco@changaco.net>
parents: 140
diff changeset
272 sockets = filter(lambda x: x and not isinstance(x, basestring), sockets)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
273 if sockets:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
274 (i, o, e) = select.select(sockets, [], [], timeout)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
275 self.process_data(i)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
276 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
277 time.sleep(timeout)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
278 self.process_timeout()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
279
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
280 def process_forever(self, timeout=0.2):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
281 """Run an infinite loop, processing data from connections.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
282
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
283 This method repeatedly calls process_once.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
284
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
285 Arguments:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
286
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
287 timeout -- Parameter to pass to process_once.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
288 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
289 while 1:
155
63db565438bd fixed the halt command
Charly COSTE <changaco@changaco.net>
parents: 149
diff changeset
290 if self.bot.halt:
63db565438bd fixed the halt command
Charly COSTE <changaco@changaco.net>
parents: 149
diff changeset
291 self.disconnect_all(message='Stopping bot')
63db565438bd fixed the halt command
Charly COSTE <changaco@changaco.net>
parents: 149
diff changeset
292 break
147
0aa31a2b9316 moved exception handling in IRC thread from process_data() to process_forever() where it belongs
Charly COSTE <changaco@changaco.net>
parents: 146
diff changeset
293 try:
0aa31a2b9316 moved exception handling in IRC thread from process_data() to process_forever() where it belongs
Charly COSTE <changaco@changaco.net>
parents: 146
diff changeset
294 self.process_once(timeout)
218
ca22fdea1c17 (irclib) minor fixes for 9e494bf91d13f165af272b7bef9422a4ea9100eb (auto-reconnection improvement)
Charly COSTE <changaco@changaco.net>
parents: 210
diff changeset
295 except ServerNotConnectedError as e:
ca22fdea1c17 (irclib) minor fixes for 9e494bf91d13f165af272b7bef9422a4ea9100eb (auto-reconnection improvement)
Charly COSTE <changaco@changaco.net>
parents: 210
diff changeset
296 if len(e.args) > 0:
ca22fdea1c17 (irclib) minor fixes for 9e494bf91d13f165af272b7bef9422a4ea9100eb (auto-reconnection improvement)
Charly COSTE <changaco@changaco.net>
parents: 210
diff changeset
297 c = e.args[0]
ca22fdea1c17 (irclib) minor fixes for 9e494bf91d13f165af272b7bef9422a4ea9100eb (auto-reconnection improvement)
Charly COSTE <changaco@changaco.net>
parents: 210
diff changeset
298 else:
ca22fdea1c17 (irclib) minor fixes for 9e494bf91d13f165af272b7bef9422a4ea9100eb (auto-reconnection improvement)
Charly COSTE <changaco@changaco.net>
parents: 210
diff changeset
299 self.bot.error(say_levels.error, 'Unkonwn exception on IRC thread:\n'+str(e.args))
ca22fdea1c17 (irclib) minor fixes for 9e494bf91d13f165af272b7bef9422a4ea9100eb (auto-reconnection improvement)
Charly COSTE <changaco@changaco.net>
parents: 210
diff changeset
300 continue
236
8acbfda313b9 use ServerConnection.nickname instead of .real_nickname in most cases, make sure we put a string in .real_nickname
Charly COSTE <changaco@changaco.net>
parents: 234
diff changeset
301 if c.nickname == self.bot.nickname:
210
fb0cf6bf9eab (irclib) moved ServerNotConnectedError handling from IRC.process_data() to IRC.process_forever() in order to always catch it
Charly COSTE <changaco@changaco.net>
parents: 209
diff changeset
302 self.bot.restart(message='Lost bot IRC connection')
fb0cf6bf9eab (irclib) moved ServerNotConnectedError handling from IRC.process_data() to IRC.process_forever() in order to always catch it
Charly COSTE <changaco@changaco.net>
parents: 209
diff changeset
303 else:
fb0cf6bf9eab (irclib) moved ServerNotConnectedError handling from IRC.process_data() to IRC.process_forever() in order to always catch it
Charly COSTE <changaco@changaco.net>
parents: 209
diff changeset
304 c.disconnect(volontary=True)
fb0cf6bf9eab (irclib) moved ServerNotConnectedError handling from IRC.process_data() to IRC.process_forever() in order to always catch it
Charly COSTE <changaco@changaco.net>
parents: 209
diff changeset
305 c.connect()
147
0aa31a2b9316 moved exception handling in IRC thread from process_data() to process_forever() where it belongs
Charly COSTE <changaco@changaco.net>
parents: 146
diff changeset
306 except:
180
102f895347ff added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents: 174
diff changeset
307 self.bot.error(say_levels.error, 'Unkonwn exception on IRC thread:\n'+traceback.format_exc(), send_to_admins=True)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
308
158
73b6c8d20da7 fixed IRC.disconnect_all() (added "volontary" argument)
Charly COSTE <changaco@changaco.net>
parents: 155
diff changeset
309 def disconnect_all(self, message="", volontary=True):
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
310 """Disconnects all connections."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
311 for c in self.connections:
158
73b6c8d20da7 fixed IRC.disconnect_all() (added "volontary" argument)
Charly COSTE <changaco@changaco.net>
parents: 155
diff changeset
312 c.disconnect(message, volontary=volontary)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
313
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
314 def add_global_handler(self, event, handler, priority=0):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
315 """Adds a global handler function for a specific event type.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
316
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
317 Arguments:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
318
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
319 event -- Event type (a string). Check the values of the
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
320 numeric_events dictionary in irclib.py for possible event
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
321 types.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
322
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
323 handler -- Callback function.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
324
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
325 priority -- A number (the lower number, the higher priority).
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
326
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
327 The handler function is called whenever the specified event is
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
328 triggered in any of the connections. See documentation for
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
329 the Event class.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
330
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
331 The handler functions are called in priority order (lowest
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
332 number is highest priority). If a handler function returns
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
333 \"NO MORE\", no more handlers will be called.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
334 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
335 if not event in self.handlers:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
336 self.handlers[event] = []
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
337 bisect.insort(self.handlers[event], ((priority, handler)))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
338
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
339 def remove_global_handler(self, event, handler):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
340 """Removes a global handler function.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
341
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
342 Arguments:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
343
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
344 event -- Event type (a string).
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
345
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
346 handler -- Callback function.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
347
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
348 Returns 1 on success, otherwise 0.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
349 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
350 if not event in self.handlers:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
351 return 0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
352 for h in self.handlers[event]:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
353 if handler == h[1]:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
354 self.handlers[event].remove(h)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
355 return 1
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
356
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
357 def execute_at(self, at, function, arguments=()):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
358 """Execute a function at a specified time.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
359
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
360 Arguments:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
361
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
362 at -- Execute at this time (standard \"time_t\" time).
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
363
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
364 function -- Function to call.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
365
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
366 arguments -- Arguments to give the function.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
367 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
368 self.execute_delayed(at-time.time(), function, arguments)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
369
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
370 def execute_delayed(self, delay, function, arguments=()):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
371 """Execute a function after a specified time.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
372
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
373 Arguments:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
374
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
375 delay -- How many seconds to wait.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
376
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
377 function -- Function to call.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
378
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
379 arguments -- Arguments to give the function.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
380 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
381 bisect.insort(self.delayed_commands, (delay+time.time(), function, arguments))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
382 if self.fn_to_add_timeout:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
383 self.fn_to_add_timeout(delay)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
384
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
385 def dcc(self, dcctype="chat"):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
386 """Creates and returns a DCCConnection object.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
387
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
388 Arguments:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
389
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
390 dcctype -- "chat" for DCC CHAT connections or "raw" for
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
391 DCC SEND (or other DCC types). If "chat",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
392 incoming data will be split in newline-separated
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
393 chunks. If "raw", incoming data is not touched.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
394 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
395 c = DCCConnection(self, dcctype)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
396 self.connections.append(c)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
397 return c
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
398
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
399 def _handle_event(self, connection, event):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
400 """[Internal]"""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
401 h = self.handlers
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
402 for handler in h.get("all_events", []) + h.get(event.eventtype(), []):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
403 if handler[1](connection, event) == "NO MORE":
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
404 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
405
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
406 def _remove_connection(self, connection):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
407 """[Internal]"""
24
4e1f27ea527b First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents: 23
diff changeset
408 if connection in self.connections:
4e1f27ea527b First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents: 23
diff changeset
409 self.connections.remove(connection)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
410 if self.fn_to_remove_socket:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
411 self.fn_to_remove_socket(connection._get_socket())
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
412
260
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
413
266
c726e8b28318 (irclib) new exception UnknownChannel raised in ServerConnection.part
Charly COSTE <changaco@changaco.net>
parents: 264
diff changeset
414 class UnknownChannel(IRCError): pass
c726e8b28318 (irclib) new exception UnknownChannel raised in ServerConnection.part
Charly COSTE <changaco@changaco.net>
parents: 264
diff changeset
415
260
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
416 LEFT, LEAVING, NOT_IN, JOINING, JOINED = range(5)
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
417
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
418 class Channel:
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
419
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
420 def __init__(self, connection, channel_name):
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
421 self.connection = connection
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
422 self.channel_name = channel_name
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
423 self.callbacks = []
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
424 self.state = NOT_IN
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
425
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
426 def _callback(self, error):
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
427 if not error:
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
428 self.state = JOINED
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
429 else:
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
430 self.state = NOT_IN
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
431 m = 'channel "'+self.channel_name+'" on connection "'+str(self.connection)+'"'
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
432 if len(self.callbacks) == 0:
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
433 self.connection.irclibobj.bot.error(1, 'no join callback for '+m, debug=True)
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
434 else:
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
435 self.connection.irclibobj.bot.error(1, 'calling '+str(len(self.callbacks))+' join callback(s) for '+m, debug=True)
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
436 for f in self.callbacks:
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
437 f(self.channel_name, error)
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
438
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
439 def add_callback(self, callback):
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
440 if callback and not callback in self.callbacks:
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
441 self.callbacks.append(callback)
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
442
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
443 def join(self, key=None, callback=None):
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
444 self.state = JOINING
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
445 self.key = key
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
446 self.add_callback(callback)
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
447 self.connection.send_raw("JOIN %s%s" % (self.channel_name, (key and (" " + key))))
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
448
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
449 def part(self, message=None):
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
450 if self.state <= NOT_IN:
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
451 return
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
452 self.state = LEAVING
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
453 self.connection.send_raw("PART " + self.channel_name + (message and (" " + message)))
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
454
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
455 def rejoin(self):
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
456 self.join(key=self.key)
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
457
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
458 def remove_callback(self, callback):
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
459 try:
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
460 self.callbacks.remove(callback)
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
461 except ValueError:
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
462 pass
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
463
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
464
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
465 _rfc_1459_command_regexp = re.compile("^(:(?P<prefix>[^ ]+) +)?(?P<command>[^ ]+)( *(?P<argument> .+))?")
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
466
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
467 class Connection:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
468 """Base class for IRC connections.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
469
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
470 Must be overridden.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
471 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
472 def __init__(self, irclibobj):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
473 self.irclibobj = irclibobj
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
474
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
475 def _get_socket():
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
476 raise IRCError, "Not overridden"
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
477
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
478 ##############################
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
479 ### Convenience wrappers.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
480
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
481 def execute_at(self, at, function, arguments=()):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
482 self.irclibobj.execute_at(at, function, arguments)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
483
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
484 def execute_delayed(self, delay, function, arguments=()):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
485 self.irclibobj.execute_delayed(delay, function, arguments)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
486
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
487
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
488 class ServerConnectionError(IRCError):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
489 pass
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
490
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
491 class ServerNotConnectedError(ServerConnectionError):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
492 pass
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
493
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
494
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
495 # Huh!? Crrrrazy EFNet doesn't follow the RFC: their ircd seems to
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
496 # use \n as message separator! :P
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
497 _linesep_regexp = re.compile("\r?\n")
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
498
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
499 class ServerConnection(Connection):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
500 """This class represents an IRC server connection.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
501
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
502 ServerConnection objects are instantiated by calling the server
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
503 method on an IRC object.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
504 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
505
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
506 def __init__(self, irclibobj, server, port, nickname):
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
507 Connection.__init__(self, irclibobj)
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
508 self.connected = False # Not connected yet.
219
63289aa1dea7 moved "nicknametoolong" and ServerConnection.really_connected handling to irclib, renamed ServerConnection.really_connected to .logged_in
Charly COSTE <changaco@changaco.net>
parents: 218
diff changeset
509 self.logged_in = False
174
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
510 self.used_by = 0
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
511 self.socket = None
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
512 self.ssl = None
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
513 self.server = server
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
514 self.port = port
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
515 self.nickname = nickname
174
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
516 self.nick_callbacks = []
224
8e6a0b60eed1 (irclib) created a callback mechanism for join
Charly COSTE <changaco@changaco.net>
parents: 223
diff changeset
517 self.join_callbacks = {}
43
9f72353e4064 Minor change to irclib.py
Charly COSTE <changaco@changaco.net>
parents: 35
diff changeset
518 self.lock = threading.RLock()
260
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
519 self.channels = {}
253
e64b574afa8f (irclib) moved initialization stuff from .connect to .__init__
Charly COSTE <changaco@changaco.net>
parents: 236
diff changeset
520 self.irc_id = None
e64b574afa8f (irclib) moved initialization stuff from .connect to .__init__
Charly COSTE <changaco@changaco.net>
parents: 236
diff changeset
521 self.previous_buffer = ""
e64b574afa8f (irclib) moved initialization stuff from .connect to .__init__
Charly COSTE <changaco@changaco.net>
parents: 236
diff changeset
522 self.handlers = {}
e64b574afa8f (irclib) moved initialization stuff from .connect to .__init__
Charly COSTE <changaco@changaco.net>
parents: 236
diff changeset
523 self.real_server_name = ""
e64b574afa8f (irclib) moved initialization stuff from .connect to .__init__
Charly COSTE <changaco@changaco.net>
parents: 236
diff changeset
524 self.new_nickname = None
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
525
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
526
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
527 def __str__(self):
172
64a0e9636ae6 removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents: 167
diff changeset
528 return self.real_nickname+' at '+self._server_str()
64a0e9636ae6 removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents: 167
diff changeset
529
64a0e9636ae6 removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents: 167
diff changeset
530
64a0e9636ae6 removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents: 167
diff changeset
531 def _decode(self, bytes):
64a0e9636ae6 removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents: 167
diff changeset
532 charsets = self.irclibobj.charsets[self._server_str()] or self.irclibobj.charsets['']
64a0e9636ae6 removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents: 167
diff changeset
533 for codec in charsets:
64a0e9636ae6 removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents: 167
diff changeset
534 try:
64a0e9636ae6 removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents: 167
diff changeset
535 return bytes.decode(codec)
64a0e9636ae6 removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents: 167
diff changeset
536 except (UnicodeEncodeError, UnicodeDecodeError):
64a0e9636ae6 removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents: 167
diff changeset
537 pass
64a0e9636ae6 removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents: 167
diff changeset
538 raise Exception, 'no suitable codec found for: '+repr(bytes)+'\ntried: '+' '.join(charsets)
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
539
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
540
75
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 74
diff changeset
541 def _ping(self):
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 74
diff changeset
542 self.irclibobj.execute_delayed(60, self._ping)
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 74
diff changeset
543 if self.connected == False:
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 74
diff changeset
544 return
180
102f895347ff added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents: 174
diff changeset
545 self.irclibobj.bot.error(1, 'sending IRC ping', debug=True)
75
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 74
diff changeset
546 self.ping(self.get_server_name())
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 74
diff changeset
547
6034087b1d10 First hack at pings
Charly COSTE <changaco@changaco.net>
parents: 74
diff changeset
548
172
64a0e9636ae6 removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents: 167
diff changeset
549 def _server_str(self):
64a0e9636ae6 removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents: 167
diff changeset
550 return self.server+':'+str(self.port)
64a0e9636ae6 removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents: 167
diff changeset
551
64a0e9636ae6 removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents: 167
diff changeset
552
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
553 def connect(self, password=None, username=None,
172
64a0e9636ae6 removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents: 167
diff changeset
554 ircname=None, localaddress="", localport=0, ssl=False, ipv6=False, nick_callback=None, charsets=None):
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
555 """Connect to the server.
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
556
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
557 Arguments:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
558
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
559 password -- Password (if any).
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
560
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
561 username -- The username.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
562
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
563 ircname -- The IRC name ("realname").
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
564
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
565 localaddress -- Bind the connection to a specific local IP address.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
566
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
567 localport -- Bind the connection to a specific local port.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
568
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
569 ssl -- Enable support for ssl.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
570
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
571 ipv6 -- Enable support for ipv6.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
572
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
573 This function can be called to reconnect a closed connection.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
574
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
575 Returns the ServerConnection object.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
576 """
24
4e1f27ea527b First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents: 23
diff changeset
577
43
9f72353e4064 Minor change to irclib.py
Charly COSTE <changaco@changaco.net>
parents: 35
diff changeset
578 self.lock.acquire()
24
4e1f27ea527b First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents: 23
diff changeset
579
174
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
580 if nick_callback:
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
581 self.add_nick_callback(nick_callback)
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
582
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
583 if self.used_by > 0:
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
584 self.used_by += 1
180
102f895347ff added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents: 174
diff changeset
585 self.irclibobj.bot.error(3, 'using existing IRC connection for '+self.__str__()+', this connection is now used by '+str(self.used_by)+' bridges', debug=True)
219
63289aa1dea7 moved "nicknametoolong" and ServerConnection.really_connected handling to irclib, renamed ServerConnection.really_connected to .logged_in
Charly COSTE <changaco@changaco.net>
parents: 218
diff changeset
586 if self.logged_in:
68
7aa1f59800b0 Fixed IRC nick callback
Charly COSTE <changaco@changaco.net>
parents: 67
diff changeset
587 self._call_nick_callbacks(None)
24
4e1f27ea527b First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents: 23
diff changeset
588 self.lock.release()
4e1f27ea527b First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents: 23
diff changeset
589 return self
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
590
136
7dc6a1764c4f handle irclib.ServerNotConnectedError
Charly COSTE <changaco@changaco.net>
parents: 131
diff changeset
591 if self.socket != 'closed':
174
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
592 self.used_by = 1
172
64a0e9636ae6 removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents: 167
diff changeset
593 if charsets or not self.irclibobj.charsets.has_key(self._server_str()):
64a0e9636ae6 removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents: 167
diff changeset
594 self.irclibobj.charsets[self._server_str()] = charsets
136
7dc6a1764c4f handle irclib.ServerNotConnectedError
Charly COSTE <changaco@changaco.net>
parents: 131
diff changeset
595 self.real_nickname = self.nickname
7dc6a1764c4f handle irclib.ServerNotConnectedError
Charly COSTE <changaco@changaco.net>
parents: 131
diff changeset
596 self.username = username or self.nickname
7dc6a1764c4f handle irclib.ServerNotConnectedError
Charly COSTE <changaco@changaco.net>
parents: 131
diff changeset
597 self.ircname = ircname or self.nickname
7dc6a1764c4f handle irclib.ServerNotConnectedError
Charly COSTE <changaco@changaco.net>
parents: 131
diff changeset
598 self.password = password
7dc6a1764c4f handle irclib.ServerNotConnectedError
Charly COSTE <changaco@changaco.net>
parents: 131
diff changeset
599 self.localaddress = localaddress
7dc6a1764c4f handle irclib.ServerNotConnectedError
Charly COSTE <changaco@changaco.net>
parents: 131
diff changeset
600 self.localport = localport
7dc6a1764c4f handle irclib.ServerNotConnectedError
Charly COSTE <changaco@changaco.net>
parents: 131
diff changeset
601 self.localhost = socket.gethostname()
174
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
602 self.ssl = ssl
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
603 self.ipv6 = ipv6
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
604
174
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
605 self.irclibobj.connection_stacks[self._server_str()].append( (self._connect, ()) )
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
606
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
607 self.lock.release()
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
608 return self
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
609
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
610
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
611 def _connect(self):
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
612
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
613 self._ping()
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
614
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
615 self.lock.acquire()
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
616
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
617 if self.socket != 'closed':
180
102f895347ff added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents: 174
diff changeset
618 self.irclibobj.bot.error(3, 'opening new IRC connection for '+self.__str__(), debug=True)
136
7dc6a1764c4f handle irclib.ServerNotConnectedError
Charly COSTE <changaco@changaco.net>
parents: 131
diff changeset
619 else:
180
102f895347ff added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents: 174
diff changeset
620 self.irclibobj.bot.error(3, 'reopening IRC connection for '+self.__str__(), debug=True)
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
621
174
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
622 if self.ipv6:
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
623 self.socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
624 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
625 self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
626 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
627 self.socket.bind((self.localaddress, self.localport))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
628 self.socket.connect((self.server, self.port))
174
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
629 if self.ssl:
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
630 self.ssl = socket.ssl(self.socket)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
631 except socket.error, x:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
632 self.socket.close()
136
7dc6a1764c4f handle irclib.ServerNotConnectedError
Charly COSTE <changaco@changaco.net>
parents: 131
diff changeset
633 self.socket = 'closed'
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
634 raise ServerConnectionError, "Couldn't connect to socket: %s" % x
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
635 self.connected = True
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
636 if self.irclibobj.fn_to_add_socket:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
637 self.irclibobj.fn_to_add_socket(self.socket)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
638
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
639 # Log on...
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
640 if self.password:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
641 self.pass_(self.password)
174
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
642 if self.nick(self.nickname):
56
b048c4c03b00 Fixed encoding issues
Charly COSTE <changaco@changaco.net>
parents: 43
diff changeset
643 self.user(self.username, self.ircname)
174
c158ad24ef3c moved irc connection interval handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 172
diff changeset
644
196
4011838e098e [irclib] handle ServerNotConnectedError in part() and quit(), we now keep track of channels we're in and rejoin them after a disconnection
Charly COSTE <changaco@changaco.net>
parents: 180
diff changeset
645 # Rejoin channels
4011838e098e [irclib] handle ServerNotConnectedError in part() and quit(), we now keep track of channels we're in and rejoin them after a disconnection
Charly COSTE <changaco@changaco.net>
parents: 180
diff changeset
646 if len(self.channels) > 0:
260
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
647 for channel in self.channels.itervalues():
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
648 channel.rejoin()
196
4011838e098e [irclib] handle ServerNotConnectedError in part() and quit(), we now keep track of channels we're in and rejoin them after a disconnection
Charly COSTE <changaco@changaco.net>
parents: 180
diff changeset
649
24
4e1f27ea527b First hack at locks for thread safety. Some other minor changes.
Charly COSTE <changaco@changaco.net>
parents: 23
diff changeset
650 self.lock.release()
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
651 return self
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
652
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
653
231
5f1e9211af03 fix for 48ad162772b79740e8ff580bde2c250b9957c126, we do need arguments in nick callbacks
Charly COSTE <changaco@changaco.net>
parents: 224
diff changeset
654 def _call_nick_callbacks(self, error, arguments=[]):
222
1439d3274e6a (irclib) minor changes to _call_nick_callbacks
Charly COSTE <changaco@changaco.net>
parents: 221
diff changeset
655 if len(self.nick_callbacks) == 0:
180
102f895347ff added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents: 174
diff changeset
656 self.irclibobj.bot.error(1, 'no nick callback for "'+self.__str__()+'"', debug=True)
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
657 else:
222
1439d3274e6a (irclib) minor changes to _call_nick_callbacks
Charly COSTE <changaco@changaco.net>
parents: 221
diff changeset
658 self.irclibobj.bot.error(1, 'calling '+str(len(self.nick_callbacks))+' nick callback(s) for "'+self.__str__()+'"', debug=True)
1439d3274e6a (irclib) minor changes to _call_nick_callbacks
Charly COSTE <changaco@changaco.net>
parents: 221
diff changeset
659 for f in self.nick_callbacks:
231
5f1e9211af03 fix for 48ad162772b79740e8ff580bde2c250b9957c126, we do need arguments in nick callbacks
Charly COSTE <changaco@changaco.net>
parents: 224
diff changeset
660 f(error, arguments=arguments)
222
1439d3274e6a (irclib) minor changes to _call_nick_callbacks
Charly COSTE <changaco@changaco.net>
parents: 221
diff changeset
661 self.nick_callbacks = []
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
662
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
663
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
664 def add_nick_callback(self, callback):
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
665 self.nick_callbacks.append(callback)
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
666
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
667
224
8e6a0b60eed1 (irclib) created a callback mechanism for join
Charly COSTE <changaco@changaco.net>
parents: 223
diff changeset
668 def add_join_callback(self, channel, callback):
8e6a0b60eed1 (irclib) created a callback mechanism for join
Charly COSTE <changaco@changaco.net>
parents: 223
diff changeset
669 self.lock.acquire()
8e6a0b60eed1 (irclib) created a callback mechanism for join
Charly COSTE <changaco@changaco.net>
parents: 223
diff changeset
670 if not self.join_callbacks.has_key(channel):
8e6a0b60eed1 (irclib) created a callback mechanism for join
Charly COSTE <changaco@changaco.net>
parents: 223
diff changeset
671 self.join_callbacks[channel] = []
8e6a0b60eed1 (irclib) created a callback mechanism for join
Charly COSTE <changaco@changaco.net>
parents: 223
diff changeset
672 self.join_callbacks[channel].append(callback)
8e6a0b60eed1 (irclib) created a callback mechanism for join
Charly COSTE <changaco@changaco.net>
parents: 223
diff changeset
673 self.lock.release()
8e6a0b60eed1 (irclib) created a callback mechanism for join
Charly COSTE <changaco@changaco.net>
parents: 223
diff changeset
674
8e6a0b60eed1 (irclib) created a callback mechanism for join
Charly COSTE <changaco@changaco.net>
parents: 223
diff changeset
675
64
8fc496eaa17b Handle IRC "nickcollision" event
Charly COSTE <changaco@changaco.net>
parents: 63
diff changeset
676 def close(self, message, volontary=True):
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
677 """Close the connection.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
678
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
679 This method closes the connection permanently; after it has
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
680 been called, the object is unusable.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
681 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
682
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
683 self.irclibobj._remove_connection(self)
128
e1e66c563d08 minor fixes in irclib
Charly COSTE <changaco@changaco.net>
parents: 125
diff changeset
684 self.disconnect(message=message, volontary=volontary)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
685
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
686 def _get_socket(self):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
687 """[Internal]"""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
688 return self.socket
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
689
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
690 def get_server_name(self):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
691 """Get the (real) server name.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
692
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
693 This method returns the (real) server name, or, more
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
694 specifically, what the server calls itself.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
695 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
696
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
697 if self.real_server_name:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
698 return self.real_server_name
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
699 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
700 return ""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
701
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
702 def process_data(self):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
703 """[Internal]"""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
704
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
705 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
706 if self.ssl:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
707 new_data = self.ssl.read(2**14)
159
da2f2dc61e74 fix in irclib, needed because ServerConnection.socket can be a string since 42d7b622776196149c9a9a05da134a85ee9509c6
Charly COSTE <changaco@changaco.net>
parents: 158
diff changeset
708 elif self.socket and hasattr(self.socket, 'recv'):
128
e1e66c563d08 minor fixes in irclib
Charly COSTE <changaco@changaco.net>
parents: 125
diff changeset
709 new_data = self.socket.recv(2**14)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
710 else:
128
e1e66c563d08 minor fixes in irclib
Charly COSTE <changaco@changaco.net>
parents: 125
diff changeset
711 return
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
712 except socket.error, x:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
713 # The server hung up.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
714 self.disconnect("Connection reset by peer")
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
715 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
716 if not new_data:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
717 # Read nothing: connection must be down.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
718 self.disconnect("Connection reset by peer")
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
719 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
720
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
721 lines = _linesep_regexp.split(self.previous_buffer + new_data)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
722
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
723 # Save the last, unfinished line.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
724 self.previous_buffer = lines.pop()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
725
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
726 for line in lines:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
727 if DEBUG:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
728 print "FROM SERVER:", line
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
729
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
730 if not line:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
731 continue
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
732
172
64a0e9636ae6 removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents: 167
diff changeset
733 line = self._decode(line)
64a0e9636ae6 removed encoding.py, charsets handling is now in irclib and custom charsets can be set per server in the configuration file
Charly COSTE <changaco@changaco.net>
parents: 167
diff changeset
734
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
735 prefix = None
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
736 command = None
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
737 arguments = None
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
738 self._handle_event(Event("all_raw_messages",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
739 self.get_server_name(),
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
740 None,
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
741 [line]))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
742
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
743 m = _rfc_1459_command_regexp.match(line)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
744 if m.group("prefix"):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
745 prefix = m.group("prefix")
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
746 if not self.real_server_name:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
747 self.real_server_name = prefix
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
748
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
749 if m.group("command"):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
750 command = m.group("command").lower()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
751
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
752 if m.group("argument"):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
753 a = m.group("argument").split(" :", 1)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
754 arguments = a[0].split()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
755 if len(a) == 2:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
756 arguments.append(a[1])
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
757
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
758 # Translate numerics into more readable strings.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
759 if command in numeric_events:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
760 command = numeric_events[command]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
761
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
762 if command in ["privmsg", "notice"]:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
763 target, message = arguments[0], arguments[1]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
764 messages = _ctcp_dequote(message)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
765
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
766 if command == "privmsg":
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
767 if is_channel(target):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
768 command = "pubmsg"
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
769 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
770 if is_channel(target):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
771 command = "pubnotice"
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
772 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
773 command = "privnotice"
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
774
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
775 for m in messages:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
776 if type(m) is types.TupleType:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
777 if command in ["privmsg", "pubmsg"]:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
778 command = "ctcp"
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
779 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
780 command = "ctcpreply"
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
781
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
782 m = list(m)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
783 if DEBUG:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
784 print "command: %s, source: %s, target: %s, arguments: %s" % (
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
785 command, prefix, target, m)
69
0a2b9e84bbde Strip colors from IRC messages
Charly COSTE <changaco@changaco.net>
parents: 68
diff changeset
786
74
676c2d2bf240 Strip bold character from IRC messages
Charly COSTE <changaco@changaco.net>
parents: 71
diff changeset
787 # Remove formatting
69
0a2b9e84bbde Strip colors from IRC messages
Charly COSTE <changaco@changaco.net>
parents: 68
diff changeset
788 for i in range(len(m)):
74
676c2d2bf240 Strip bold character from IRC messages
Charly COSTE <changaco@changaco.net>
parents: 71
diff changeset
789 m[i] = strip_formatting_re.sub('', m[i])
69
0a2b9e84bbde Strip colors from IRC messages
Charly COSTE <changaco@changaco.net>
parents: 68
diff changeset
790
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
791 self._handle_event(Event(command, prefix, target, m))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
792 if command == "ctcp" and m[0] == "ACTION":
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
793 self._handle_event(Event("action", prefix, target, m[1:]))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
794 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
795 if DEBUG:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
796 print "command: %s, source: %s, target: %s, arguments: %s" % (
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
797 command, prefix, target, [m])
74
676c2d2bf240 Strip bold character from IRC messages
Charly COSTE <changaco@changaco.net>
parents: 71
diff changeset
798 self._handle_event(Event(command, prefix, target, [strip_formatting_re.sub('', m)]))
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
799 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
800 target = None
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
801
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
802 if command == "quit":
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
803 arguments = [arguments[0]]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
804 elif command == "ping":
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
805 target = arguments[0]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
806 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
807 target = arguments[0]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
808 arguments = arguments[1:]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
809
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
810 if command == "mode":
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
811 if not is_channel(target):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
812 command = "umode"
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
813
234
c9c0d9a5e0b8 (irclib) tried to fix nick callbacks
Charly COSTE <changaco@changaco.net>
parents: 231
diff changeset
814 if command in ["nick", "welcome"]:
c9c0d9a5e0b8 (irclib) tried to fix nick callbacks
Charly COSTE <changaco@changaco.net>
parents: 231
diff changeset
815 self.logged_in = True
236
8acbfda313b9 use ServerConnection.nickname instead of .real_nickname in most cases, make sure we put a string in .real_nickname
Charly COSTE <changaco@changaco.net>
parents: 234
diff changeset
816 if self.new_nickname and isinstance(target, basestring):
8acbfda313b9 use ServerConnection.nickname instead of .real_nickname in most cases, make sure we put a string in .real_nickname
Charly COSTE <changaco@changaco.net>
parents: 234
diff changeset
817 self.real_nickname = target
234
c9c0d9a5e0b8 (irclib) tried to fix nick callbacks
Charly COSTE <changaco@changaco.net>
parents: 231
diff changeset
818 if self.new_nickname != target:
c9c0d9a5e0b8 (irclib) tried to fix nick callbacks
Charly COSTE <changaco@changaco.net>
parents: 231
diff changeset
819 if len(self.new_nickname) > len(target):
c9c0d9a5e0b8 (irclib) tried to fix nick callbacks
Charly COSTE <changaco@changaco.net>
parents: 231
diff changeset
820 self._handle_event(Event('nicknametoolong', None, None, None))
c9c0d9a5e0b8 (irclib) tried to fix nick callbacks
Charly COSTE <changaco@changaco.net>
parents: 231
diff changeset
821 else:
c9c0d9a5e0b8 (irclib) tried to fix nick callbacks
Charly COSTE <changaco@changaco.net>
parents: 231
diff changeset
822 self._handle_event(Event('erroneusnickname', None, None, None))
c9c0d9a5e0b8 (irclib) tried to fix nick callbacks
Charly COSTE <changaco@changaco.net>
parents: 231
diff changeset
823 else:
c9c0d9a5e0b8 (irclib) tried to fix nick callbacks
Charly COSTE <changaco@changaco.net>
parents: 231
diff changeset
824 self._call_nick_callbacks(None)
c9c0d9a5e0b8 (irclib) tried to fix nick callbacks
Charly COSTE <changaco@changaco.net>
parents: 231
diff changeset
825 self.new_nickname = None
c9c0d9a5e0b8 (irclib) tried to fix nick callbacks
Charly COSTE <changaco@changaco.net>
parents: 231
diff changeset
826
221
1a82d5d40d90 moved irc_id handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 219
diff changeset
827 if command == "join":
223
3da85bf56bdf (irclib) minor fix, only show the irc_id once in the debug log
Charly COSTE <changaco@changaco.net>
parents: 222
diff changeset
828 if self.irc_id != prefix:
3da85bf56bdf (irclib) minor fix, only show the irc_id once in the debug log
Charly COSTE <changaco@changaco.net>
parents: 222
diff changeset
829 self.irc_id = prefix
3da85bf56bdf (irclib) minor fix, only show the irc_id once in the debug log
Charly COSTE <changaco@changaco.net>
parents: 222
diff changeset
830 if DEBUG:
3da85bf56bdf (irclib) minor fix, only show the irc_id once in the debug log
Charly COSTE <changaco@changaco.net>
parents: 222
diff changeset
831 print "irc_id: %s" % (prefix)
224
8e6a0b60eed1 (irclib) created a callback mechanism for join
Charly COSTE <changaco@changaco.net>
parents: 223
diff changeset
832 channel = target.lower()
260
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
833 if self.channels[channel].state != JOINED:
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
834 self.channels[channel]._callback(None)
224
8e6a0b60eed1 (irclib) created a callback mechanism for join
Charly COSTE <changaco@changaco.net>
parents: 223
diff changeset
835
8e6a0b60eed1 (irclib) created a callback mechanism for join
Charly COSTE <changaco@changaco.net>
parents: 223
diff changeset
836 if command in ['inviteonlychan', 'bannedfromchan', 'channelisfull', 'badchannelkey']:
260
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
837 self.channels[arguments[0].lower()]._callback(command)
221
1a82d5d40d90 moved irc_id handling to irclib
Charly COSTE <changaco@changaco.net>
parents: 219
diff changeset
838
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
839 if DEBUG:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
840 print "command: %s, source: %s, target: %s, arguments: %s" % (
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
841 command, prefix, target, arguments)
69
0a2b9e84bbde Strip colors from IRC messages
Charly COSTE <changaco@changaco.net>
parents: 68
diff changeset
842
74
676c2d2bf240 Strip bold character from IRC messages
Charly COSTE <changaco@changaco.net>
parents: 71
diff changeset
843 # Remove formatting
69
0a2b9e84bbde Strip colors from IRC messages
Charly COSTE <changaco@changaco.net>
parents: 68
diff changeset
844 for i in range(len(arguments)):
74
676c2d2bf240 Strip bold character from IRC messages
Charly COSTE <changaco@changaco.net>
parents: 71
diff changeset
845 arguments[i] = strip_formatting_re.sub('', arguments[i])
69
0a2b9e84bbde Strip colors from IRC messages
Charly COSTE <changaco@changaco.net>
parents: 68
diff changeset
846
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
847 self._handle_event(Event(command, prefix, target, arguments))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
848
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
849 def _handle_event(self, event):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
850 """[Internal]"""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
851 self.irclibobj._handle_event(self, event)
219
63289aa1dea7 moved "nicknametoolong" and ServerConnection.really_connected handling to irclib, renamed ServerConnection.really_connected to .logged_in
Charly COSTE <changaco@changaco.net>
parents: 218
diff changeset
852 if event.eventtype() in ['disconnect', 'nicknameinuse', 'nickcollision', 'erroneusnickname', 'nicknametoolong']:
231
5f1e9211af03 fix for 48ad162772b79740e8ff580bde2c250b9957c126, we do need arguments in nick callbacks
Charly COSTE <changaco@changaco.net>
parents: 224
diff changeset
853 self._call_nick_callbacks(event.eventtype(), arguments=[event])
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
854 if event.eventtype() in self.handlers:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
855 for fn in self.handlers[event.eventtype()]:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
856 fn(self, event)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
857
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
858 def add_global_handler(self, *args):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
859 """Add global handler.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
860
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
861 See documentation for IRC.add_global_handler.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
862 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
863 self.irclibobj.add_global_handler(*args)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
864
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
865 def remove_global_handler(self, *args):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
866 """Remove global handler.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
867
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
868 See documentation for IRC.remove_global_handler.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
869 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
870 self.irclibobj.remove_global_handler(*args)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
871
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
872 def action(self, target, action):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
873 """Send a CTCP ACTION command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
874 self.ctcp("ACTION", target, action)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
875
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
876 def admin(self, server=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
877 """Send an ADMIN command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
878 self.send_raw(" ".join(["ADMIN", server]).strip())
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
879
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
880 def ctcp(self, ctcptype, target, parameter=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
881 """Send a CTCP command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
882 ctcptype = ctcptype.upper()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
883 self.privmsg(target, "\001%s%s\001" % (ctcptype, parameter and (" " + parameter) or ""))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
884
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
885 def ctcp_reply(self, target, parameter):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
886 """Send a CTCP REPLY command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
887 self.notice(target, "\001%s\001" % parameter)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
888
63
71508f22edb4 Fixed unjustified switching to limited mode
Charly COSTE <changaco@changaco.net>
parents: 57
diff changeset
889 def disconnect(self, message="", volontary=False):
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
890 """Hang up the connection.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
891
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
892 Arguments:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
893
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
894 message -- Quit message.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
895 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
896
57
ebd4278e472f Some thread safety for irclib.py
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
897 self.lock.acquire()
ebd4278e472f Some thread safety for irclib.py
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
898
163
54c0e77370fd fixed irclib.ServerConnection.disconnect()
Charly COSTE <changaco@changaco.net>
parents: 159
diff changeset
899 if self.connected:
54c0e77370fd fixed irclib.ServerConnection.disconnect()
Charly COSTE <changaco@changaco.net>
parents: 159
diff changeset
900 self.connected = False
219
63289aa1dea7 moved "nicknametoolong" and ServerConnection.really_connected handling to irclib, renamed ServerConnection.really_connected to .logged_in
Charly COSTE <changaco@changaco.net>
parents: 218
diff changeset
901 if self.logged_in:
63289aa1dea7 moved "nicknametoolong" and ServerConnection.really_connected handling to irclib, renamed ServerConnection.really_connected to .logged_in
Charly COSTE <changaco@changaco.net>
parents: 218
diff changeset
902 self.logged_in = False
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
903
163
54c0e77370fd fixed irclib.ServerConnection.disconnect()
Charly COSTE <changaco@changaco.net>
parents: 159
diff changeset
904 if self.socket and self.socket != 'closed':
167
f4997d50e93b fixed an infinite loop and an indentation error in irclib
Charly COSTE <changaco@changaco.net>
parents: 166
diff changeset
905 if message and message != 'Connection reset by peer':
f4997d50e93b fixed an infinite loop and an indentation error in irclib
Charly COSTE <changaco@changaco.net>
parents: 166
diff changeset
906 self.quit(message)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
907
163
54c0e77370fd fixed irclib.ServerConnection.disconnect()
Charly COSTE <changaco@changaco.net>
parents: 159
diff changeset
908 try:
54c0e77370fd fixed irclib.ServerConnection.disconnect()
Charly COSTE <changaco@changaco.net>
parents: 159
diff changeset
909 self.socket.close()
54c0e77370fd fixed irclib.ServerConnection.disconnect()
Charly COSTE <changaco@changaco.net>
parents: 159
diff changeset
910 except socket.error, x:
54c0e77370fd fixed irclib.ServerConnection.disconnect()
Charly COSTE <changaco@changaco.net>
parents: 159
diff changeset
911 pass
54c0e77370fd fixed irclib.ServerConnection.disconnect()
Charly COSTE <changaco@changaco.net>
parents: 159
diff changeset
912 self.socket = 'closed'
54c0e77370fd fixed irclib.ServerConnection.disconnect()
Charly COSTE <changaco@changaco.net>
parents: 159
diff changeset
913
57
ebd4278e472f Some thread safety for irclib.py
Charly COSTE <changaco@changaco.net>
parents: 56
diff changeset
914 self.lock.release()
63
71508f22edb4 Fixed unjustified switching to limited mode
Charly COSTE <changaco@changaco.net>
parents: 57
diff changeset
915
71508f22edb4 Fixed unjustified switching to limited mode
Charly COSTE <changaco@changaco.net>
parents: 57
diff changeset
916 if volontary == False:
71508f22edb4 Fixed unjustified switching to limited mode
Charly COSTE <changaco@changaco.net>
parents: 57
diff changeset
917 self._handle_event(Event("disconnect", self.server, "", [message]))
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
918
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
919 def globops(self, text):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
920 """Send a GLOBOPS command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
921 self.send_raw("GLOBOPS :" + text)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
922
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
923 def info(self, server=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
924 """Send an INFO command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
925 self.send_raw(" ".join(["INFO", server]).strip())
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
926
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
927 def invite(self, nick, channel):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
928 """Send an INVITE command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
929 self.send_raw(" ".join(["INVITE", nick, channel]).strip())
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
930
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
931 def ison(self, nicks):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
932 """Send an ISON command.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
933
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
934 Arguments:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
935
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
936 nicks -- List of nicks.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
937 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
938 self.send_raw("ISON " + " ".join(nicks))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
939
260
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
940 def join(self, channel_name, callback=None, key=""):
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
941 """Send a JOIN command."""
260
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
942 if not self.channels.has_key(channel_name):
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
943 self.channels[channel_name] = Channel(self, channel_name)
9a2302e8382b (irclib) created a "Channel" class
Charly COSTE <changaco@changaco.net>
parents: 253
diff changeset
944 self.channels[channel_name].join(key=key, callback=callback)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
945
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
946 def kick(self, channel, nick, comment=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
947 """Send a KICK command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
948 self.send_raw("KICK %s %s%s" % (channel, nick, (comment and (" :" + comment))))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
949
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
950 def links(self, remote_server="", server_mask=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
951 """Send a LINKS command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
952 command = "LINKS"
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
953 if remote_server:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
954 command = command + " " + remote_server
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
955 if server_mask:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
956 command = command + " " + server_mask
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
957 self.send_raw(command)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
958
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
959 def list(self, channels=None, server=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
960 """Send a LIST command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
961 command = "LIST"
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
962 if channels:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
963 command = command + " " + ",".join(channels)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
964 if server:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
965 command = command + " " + server
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
966 self.send_raw(command)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
967
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
968 def lusers(self, server=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
969 """Send a LUSERS command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
970 self.send_raw("LUSERS" + (server and (" " + server)))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
971
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
972 def mode(self, target, command):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
973 """Send a MODE command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
974 self.send_raw("MODE %s %s" % (target, command))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
975
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
976 def motd(self, server=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
977 """Send an MOTD command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
978 self.send_raw("MOTD" + (server and (" " + server)))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
979
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
980 def names(self, channels=None):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
981 """Send a NAMES command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
982 self.send_raw("NAMES" + (channels and (" " + ",".join(channels)) or ""))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
983
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
984 def nick(self, newnick, callback=None):
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
985 """Send a NICK command."""
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
986 if callback != None:
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
987 self.add_nick_callback(callback)
166
0fc24e232997 some fixes related to IRC nicknames
Charly COSTE <changaco@changaco.net>
parents: 165
diff changeset
988 if re.search('[ \.\']', newnick) != None:
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
989 self._call_nick_callbacks('erroneusnickname')
56
b048c4c03b00 Fixed encoding issues
Charly COSTE <changaco@changaco.net>
parents: 43
diff changeset
990 return False
b048c4c03b00 Fixed encoding issues
Charly COSTE <changaco@changaco.net>
parents: 43
diff changeset
991 try:
b048c4c03b00 Fixed encoding issues
Charly COSTE <changaco@changaco.net>
parents: 43
diff changeset
992 str(newnick)
b048c4c03b00 Fixed encoding issues
Charly COSTE <changaco@changaco.net>
parents: 43
diff changeset
993 except:
b048c4c03b00 Fixed encoding issues
Charly COSTE <changaco@changaco.net>
parents: 43
diff changeset
994 self._call_nick_callbacks('erroneusnickname')
b048c4c03b00 Fixed encoding issues
Charly COSTE <changaco@changaco.net>
parents: 43
diff changeset
995 return False
219
63289aa1dea7 moved "nicknametoolong" and ServerConnection.really_connected handling to irclib, renamed ServerConnection.really_connected to .logged_in
Charly COSTE <changaco@changaco.net>
parents: 218
diff changeset
996 self.new_nickname = newnick
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
997 self.send_raw("NICK " + newnick)
56
b048c4c03b00 Fixed encoding issues
Charly COSTE <changaco@changaco.net>
parents: 43
diff changeset
998 return True
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
999
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1000 def notice(self, target, text):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1001 """Send a NOTICE command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1002 # Should limit len(text) here!
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1003 self.send_raw("NOTICE %s :%s" % (target, text))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1004
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1005 def oper(self, nick, password):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1006 """Send an OPER command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1007 self.send_raw("OPER %s %s" % (nick, password))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1008
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1009 def part(self, channels, message=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1010 """Send a PART command."""
196
4011838e098e [irclib] handle ServerNotConnectedError in part() and quit(), we now keep track of channels we're in and rejoin them after a disconnection
Charly COSTE <changaco@changaco.net>
parents: 180
diff changeset
1011 try:
4011838e098e [irclib] handle ServerNotConnectedError in part() and quit(), we now keep track of channels we're in and rejoin them after a disconnection
Charly COSTE <changaco@changaco.net>
parents: 180
diff changeset
1012 if isinstance(channels, basestring):
266
c726e8b28318 (irclib) new exception UnknownChannel raised in ServerConnection.part
Charly COSTE <changaco@changaco.net>
parents: 264
diff changeset
1013 try:
c726e8b28318 (irclib) new exception UnknownChannel raised in ServerConnection.part
Charly COSTE <changaco@changaco.net>
parents: 264
diff changeset
1014 self.channels[channels].part(message=message)
c726e8b28318 (irclib) new exception UnknownChannel raised in ServerConnection.part
Charly COSTE <changaco@changaco.net>
parents: 264
diff changeset
1015 except KeyError:
271
18c9e8b823bc (irclib) minor fix, better UnknownChannel arguments
Charly COSTE <changaco@changaco.net>
parents: 266
diff changeset
1016 raise UnknownChannel, (channels, message, str(self))
196
4011838e098e [irclib] handle ServerNotConnectedError in part() and quit(), we now keep track of channels we're in and rejoin them after a disconnection
Charly COSTE <changaco@changaco.net>
parents: 180
diff changeset
1017 else:
4011838e098e [irclib] handle ServerNotConnectedError in part() and quit(), we now keep track of channels we're in and rejoin them after a disconnection
Charly COSTE <changaco@changaco.net>
parents: 180
diff changeset
1018 for channel in channels:
266
c726e8b28318 (irclib) new exception UnknownChannel raised in ServerConnection.part
Charly COSTE <changaco@changaco.net>
parents: 264
diff changeset
1019 try:
c726e8b28318 (irclib) new exception UnknownChannel raised in ServerConnection.part
Charly COSTE <changaco@changaco.net>
parents: 264
diff changeset
1020 self.channels[channel].part(message=message)
c726e8b28318 (irclib) new exception UnknownChannel raised in ServerConnection.part
Charly COSTE <changaco@changaco.net>
parents: 264
diff changeset
1021 except KeyError:
c726e8b28318 (irclib) new exception UnknownChannel raised in ServerConnection.part
Charly COSTE <changaco@changaco.net>
parents: 264
diff changeset
1022 raise UnknownChannel, (channel, message, self)
196
4011838e098e [irclib] handle ServerNotConnectedError in part() and quit(), we now keep track of channels we're in and rejoin them after a disconnection
Charly COSTE <changaco@changaco.net>
parents: 180
diff changeset
1023 except ServerNotConnectedError:
4011838e098e [irclib] handle ServerNotConnectedError in part() and quit(), we now keep track of channels we're in and rejoin them after a disconnection
Charly COSTE <changaco@changaco.net>
parents: 180
diff changeset
1024 self.disconnect(volontary=True)
4011838e098e [irclib] handle ServerNotConnectedError in part() and quit(), we now keep track of channels we're in and rejoin them after a disconnection
Charly COSTE <changaco@changaco.net>
parents: 180
diff changeset
1025 self.connect()
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1026
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1027 def pass_(self, password):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1028 """Send a PASS command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1029 self.send_raw("PASS " + password)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1030
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1031 def ping(self, target, target2=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1032 """Send a PING command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1033 self.send_raw("PING %s%s" % (target, target2 and (" " + target2)))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1034
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1035 def pong(self, target, target2=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1036 """Send a PONG command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1037 self.send_raw("PONG %s%s" % (target, target2 and (" " + target2)))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1038
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1039 def privmsg(self, target, text):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1040 """Send a PRIVMSG command."""
9
4b2faa511f01 Fixed multi-line message bug
Charly COSTE <changaco@changaco.net>
parents: 5
diff changeset
1041 for l in text.split('\n'):
115
0ae0f8836a7a split long messages when sending on IRC
Charly COSTE <changaco@changaco.net>
parents: 89
diff changeset
1042 l_size = len(l.encode('utf-8'))
0ae0f8836a7a split long messages when sending on IRC
Charly COSTE <changaco@changaco.net>
parents: 89
diff changeset
1043 available_size = float(510-len('%s PRIVMSG %s :' % (self.irc_id, target))) # 510 is the size limit for IRC messages defined in RFC 2812
0ae0f8836a7a split long messages when sending on IRC
Charly COSTE <changaco@changaco.net>
parents: 89
diff changeset
1044 e = 0
138
f3a9c891f7c0 fixed a DeprecationWarning in irclib
Charly COSTE <changaco@changaco.net>
parents: 136
diff changeset
1045 for i in range(int(math.ceil(l_size/available_size))):
115
0ae0f8836a7a split long messages when sending on IRC
Charly COSTE <changaco@changaco.net>
parents: 89
diff changeset
1046 s = e
0ae0f8836a7a split long messages when sending on IRC
Charly COSTE <changaco@changaco.net>
parents: 89
diff changeset
1047 e = s+int(available_size)
0ae0f8836a7a split long messages when sending on IRC
Charly COSTE <changaco@changaco.net>
parents: 89
diff changeset
1048 while len(l[s:e].encode('utf-8')) >= available_size:
0ae0f8836a7a split long messages when sending on IRC
Charly COSTE <changaco@changaco.net>
parents: 89
diff changeset
1049 e -= 1
0ae0f8836a7a split long messages when sending on IRC
Charly COSTE <changaco@changaco.net>
parents: 89
diff changeset
1050 self.send_raw("PRIVMSG %s :%s" % (target, l[s:e]))
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1051
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1052 def privmsg_many(self, targets, text):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1053 """Send a PRIVMSG command to multiple targets."""
115
0ae0f8836a7a split long messages when sending on IRC
Charly COSTE <changaco@changaco.net>
parents: 89
diff changeset
1054 # Size of targets should be limited
0ae0f8836a7a split long messages when sending on IRC
Charly COSTE <changaco@changaco.net>
parents: 89
diff changeset
1055 self.privmsg(','.join(targets), text)
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1056
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1057 def quit(self, message=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1058 """Send a QUIT command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1059 # Note that many IRC servers don't use your QUIT message
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1060 # unless you've been connected for at least 5 minutes!
196
4011838e098e [irclib] handle ServerNotConnectedError in part() and quit(), we now keep track of channels we're in and rejoin them after a disconnection
Charly COSTE <changaco@changaco.net>
parents: 180
diff changeset
1061 try:
4011838e098e [irclib] handle ServerNotConnectedError in part() and quit(), we now keep track of channels we're in and rejoin them after a disconnection
Charly COSTE <changaco@changaco.net>
parents: 180
diff changeset
1062 self.send_raw("QUIT" + (message and (" :" + message)))
4011838e098e [irclib] handle ServerNotConnectedError in part() and quit(), we now keep track of channels we're in and rejoin them after a disconnection
Charly COSTE <changaco@changaco.net>
parents: 180
diff changeset
1063 except ServerNotConnectedError:
4011838e098e [irclib] handle ServerNotConnectedError in part() and quit(), we now keep track of channels we're in and rejoin them after a disconnection
Charly COSTE <changaco@changaco.net>
parents: 180
diff changeset
1064 pass
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1065
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1066 def send_raw(self, string):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1067 """Send raw string to the server.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1068
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1069 The string will be padded with appropriate CR LF.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1070 """
146
229a59acde0f fixes in irclib, needed because ServerConnection.socket can be a string since 42d7b622776196149c9a9a05da134a85ee9509c6
Charly COSTE <changaco@changaco.net>
parents: 140
diff changeset
1071 if not self.socket or isinstance(self.socket, basestring):
136
7dc6a1764c4f handle irclib.ServerNotConnectedError
Charly COSTE <changaco@changaco.net>
parents: 131
diff changeset
1072 raise ServerNotConnectedError, self
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1073 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1074 if self.ssl:
56
b048c4c03b00 Fixed encoding issues
Charly COSTE <changaco@changaco.net>
parents: 43
diff changeset
1075 self.ssl.write(string.encode('utf-8') + "\r\n")
146
229a59acde0f fixes in irclib, needed because ServerConnection.socket can be a string since 42d7b622776196149c9a9a05da134a85ee9509c6
Charly COSTE <changaco@changaco.net>
parents: 140
diff changeset
1076 else:
56
b048c4c03b00 Fixed encoding issues
Charly COSTE <changaco@changaco.net>
parents: 43
diff changeset
1077 self.socket.send(string.encode('utf-8') + "\r\n")
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1078 if DEBUG:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1079 print "TO SERVER:", string
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1080 except socket.error, x:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1081 # Ouch!
165
12d564cd0203 minor fix in irclib, always use exactly the same message when server hung up
Charly COSTE <changaco@changaco.net>
parents: 164
diff changeset
1082 self.disconnect("Connection reset by peer")
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1083
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1084 def squit(self, server, comment=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1085 """Send an SQUIT command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1086 self.send_raw("SQUIT %s%s" % (server, comment and (" :" + comment)))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1087
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1088 def stats(self, statstype, server=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1089 """Send a STATS command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1090 self.send_raw("STATS %s%s" % (statstype, server and (" " + server)))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1091
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1092 def time(self, server=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1093 """Send a TIME command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1094 self.send_raw("TIME" + (server and (" " + server)))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1095
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1096 def topic(self, channel, new_topic=None):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1097 """Send a TOPIC command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1098 if new_topic is None:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1099 self.send_raw("TOPIC " + channel)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1100 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1101 self.send_raw("TOPIC %s :%s" % (channel, new_topic))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1102
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1103 def trace(self, target=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1104 """Send a TRACE command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1105 self.send_raw("TRACE" + (target and (" " + target)))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1106
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1107 def user(self, username, realname):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1108 """Send a USER command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1109 self.send_raw("USER %s 0 * :%s" % (username, realname))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1110
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1111 def userhost(self, nicks):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1112 """Send a USERHOST command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1113 self.send_raw("USERHOST " + ",".join(nicks))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1114
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1115 def users(self, server=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1116 """Send a USERS command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1117 self.send_raw("USERS" + (server and (" " + server)))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1118
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1119 def version(self, server=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1120 """Send a VERSION command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1121 self.send_raw("VERSION" + (server and (" " + server)))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1122
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1123 def wallops(self, text):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1124 """Send a WALLOPS command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1125 self.send_raw("WALLOPS :" + text)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1126
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1127 def who(self, target="", op=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1128 """Send a WHO command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1129 self.send_raw("WHO%s%s" % (target and (" " + target), op and (" o")))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1130
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1131 def whois(self, targets):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1132 """Send a WHOIS command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1133 self.send_raw("WHOIS " + ",".join(targets))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1134
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1135 def whowas(self, nick, max="", server=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1136 """Send a WHOWAS command."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1137 self.send_raw("WHOWAS %s%s%s" % (nick,
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1138 max and (" " + max),
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1139 server and (" " + server)))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1140
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1141 class DCCConnectionError(IRCError):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1142 pass
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1143
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1144
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1145 class DCCConnection(Connection):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1146 """This class represents a DCC connection.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1147
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1148 DCCConnection objects are instantiated by calling the dcc
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1149 method on an IRC object.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1150 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1151 def __init__(self, irclibobj, dcctype):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1152 Connection.__init__(self, irclibobj)
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
1153 self.connected = False
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1154 self.passive = 0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1155 self.dcctype = dcctype
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1156 self.peeraddress = None
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1157 self.peerport = None
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1158
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1159 def connect(self, address, port):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1160 """Connect/reconnect to a DCC peer.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1161
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1162 Arguments:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1163 address -- Host/IP address of the peer.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1164
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1165 port -- The port number to connect to.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1166
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1167 Returns the DCCConnection object.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1168 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1169 self.peeraddress = socket.gethostbyname(address)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1170 self.peerport = port
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1171 self.socket = None
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1172 self.previous_buffer = ""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1173 self.handlers = {}
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1174 self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1175 self.passive = 0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1176 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1177 self.socket.connect((self.peeraddress, self.peerport))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1178 except socket.error, x:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1179 raise DCCConnectionError, "Couldn't connect to socket: %s" % x
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
1180 self.connected = True
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1181 if self.irclibobj.fn_to_add_socket:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1182 self.irclibobj.fn_to_add_socket(self.socket)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1183 return self
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1184
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1185 def listen(self):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1186 """Wait for a connection/reconnection from a DCC peer.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1187
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1188 Returns the DCCConnection object.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1189
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1190 The local IP address and port are available as
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1191 self.localaddress and self.localport. After connection from a
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1192 peer, the peer address and port are available as
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1193 self.peeraddress and self.peerport.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1194 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1195 self.previous_buffer = ""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1196 self.handlers = {}
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1197 self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1198 self.passive = 1
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1199 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1200 self.socket.bind((socket.gethostbyname(socket.gethostname()), 0))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1201 self.localaddress, self.localport = self.socket.getsockname()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1202 self.socket.listen(10)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1203 except socket.error, x:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1204 raise DCCConnectionError, "Couldn't bind socket: %s" % x
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1205 return self
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1206
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1207 def disconnect(self, message=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1208 """Hang up the connection and close the object.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1209
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1210 Arguments:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1211
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1212 message -- Quit message.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1213 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1214 if not self.connected:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1215 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1216
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
1217 self.connected = False
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1218 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1219 self.socket.close()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1220 except socket.error, x:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1221 pass
136
7dc6a1764c4f handle irclib.ServerNotConnectedError
Charly COSTE <changaco@changaco.net>
parents: 131
diff changeset
1222 self.socket = 'closed'
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1223 self.irclibobj._handle_event(
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1224 self,
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1225 Event("dcc_disconnect", self.peeraddress, "", [message]))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1226 self.irclibobj._remove_connection(self)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1227
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1228 def process_data(self):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1229 """[Internal]"""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1230
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1231 if self.passive and not self.connected:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1232 conn, (self.peeraddress, self.peerport) = self.socket.accept()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1233 self.socket.close()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1234 self.socket = conn
17
32a35f7eff70 Rewrote/modified many things, multiple bridges should now work and are preferred over multiple bots.
Charly COSTE <changaco@changaco.net>
parents: 14
diff changeset
1235 self.connected = True
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1236 if DEBUG:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1237 print "DCC connection from %s:%d" % (
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1238 self.peeraddress, self.peerport)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1239 self.irclibobj._handle_event(
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1240 self,
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1241 Event("dcc_connect", self.peeraddress, None, None))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1242 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1243
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1244 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1245 new_data = self.socket.recv(2**14)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1246 except socket.error, x:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1247 # The server hung up.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1248 self.disconnect("Connection reset by peer")
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1249 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1250 if not new_data:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1251 # Read nothing: connection must be down.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1252 self.disconnect("Connection reset by peer")
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1253 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1254
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1255 if self.dcctype == "chat":
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1256 # The specification says lines are terminated with LF, but
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1257 # it seems safer to handle CR LF terminations too.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1258 chunks = _linesep_regexp.split(self.previous_buffer + new_data)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1259
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1260 # Save the last, unfinished line.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1261 self.previous_buffer = chunks[-1]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1262 if len(self.previous_buffer) > 2**14:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1263 # Bad peer! Naughty peer!
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1264 self.disconnect()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1265 return
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1266 chunks = chunks[:-1]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1267 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1268 chunks = [new_data]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1269
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1270 command = "dccmsg"
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1271 prefix = self.peeraddress
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1272 target = None
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1273 for chunk in chunks:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1274 if DEBUG:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1275 print "FROM PEER:", chunk
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1276 arguments = [chunk]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1277 if DEBUG:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1278 print "command: %s, source: %s, target: %s, arguments: %s" % (
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1279 command, prefix, target, arguments)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1280 self.irclibobj._handle_event(
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1281 self,
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1282 Event(command, prefix, target, arguments))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1283
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1284 def _get_socket(self):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1285 """[Internal]"""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1286 return self.socket
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1287
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1288 def privmsg(self, string):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1289 """Send data to DCC peer.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1290
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1291 The string will be padded with appropriate LF if it's a DCC
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1292 CHAT session.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1293 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1294 try:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1295 self.socket.send(string)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1296 if self.dcctype == "chat":
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1297 self.socket.send("\n")
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1298 if DEBUG:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1299 print "TO PEER: %s\n" % string
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1300 except socket.error, x:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1301 # Ouch!
165
12d564cd0203 minor fix in irclib, always use exactly the same message when server hung up
Charly COSTE <changaco@changaco.net>
parents: 164
diff changeset
1302 self.disconnect("Connection reset by peer")
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1303
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1304
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1305 class Event:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1306 """Class representing an IRC event."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1307 def __init__(self, eventtype, source, target, arguments=None):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1308 """Constructor of Event objects.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1309
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1310 Arguments:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1311
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1312 eventtype -- A string describing the event.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1313
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1314 source -- The originator of the event (a nick mask or a server).
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1315
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1316 target -- The target of the event (a nick or a channel).
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1317
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1318 arguments -- Any event specific arguments.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1319 """
149
332bb2e8e71e Revert "strip events' properties"
Charly COSTE <changaco@changaco.net>
parents: 148
diff changeset
1320 self._eventtype = eventtype
332bb2e8e71e Revert "strip events' properties"
Charly COSTE <changaco@changaco.net>
parents: 148
diff changeset
1321 self._source = source
332bb2e8e71e Revert "strip events' properties"
Charly COSTE <changaco@changaco.net>
parents: 148
diff changeset
1322 self._target = target
0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1323 if arguments:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1324 self._arguments = arguments
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1325 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1326 self._arguments = []
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1327
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1328 def eventtype(self):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1329 """Get the event type."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1330 return self._eventtype
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1331
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1332 def source(self):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1333 """Get the event source."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1334 return self._source
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1335
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1336 def target(self):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1337 """Get the event target."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1338 return self._target
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1339
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1340 def arguments(self):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1341 """Get the event arguments."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1342 return self._arguments
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1343
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1344 _LOW_LEVEL_QUOTE = "\020"
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1345 _CTCP_LEVEL_QUOTE = "\134"
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1346 _CTCP_DELIMITER = "\001"
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1347
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1348 _low_level_mapping = {
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1349 "0": "\000",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1350 "n": "\n",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1351 "r": "\r",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1352 _LOW_LEVEL_QUOTE: _LOW_LEVEL_QUOTE
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1353 }
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1354
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1355 _low_level_regexp = re.compile(_LOW_LEVEL_QUOTE + "(.)")
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1356
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1357 def mask_matches(nick, mask):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1358 """Check if a nick matches a mask.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1359
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1360 Returns true if the nick matches, otherwise false.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1361 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1362 nick = irc_lower(nick)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1363 mask = irc_lower(mask)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1364 mask = mask.replace("\\", "\\\\")
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1365 for ch in ".$|[](){}+":
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1366 mask = mask.replace(ch, "\\" + ch)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1367 mask = mask.replace("?", ".")
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1368 mask = mask.replace("*", ".*")
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1369 r = re.compile(mask, re.IGNORECASE)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1370 return r.match(nick)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1371
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1372 _special = "-[]\\`^{}"
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1373 nick_characters = string.ascii_letters + string.digits + _special
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1374 _ircstring_translation = string.maketrans(string.ascii_uppercase + "[]\\^",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1375 string.ascii_lowercase + "{}|~")
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1376
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1377 def irc_lower(s):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1378 """Returns a lowercased string.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1379
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1380 The definition of lowercased comes from the IRC specification (RFC
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1381 1459).
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1382 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1383 return s.translate(_ircstring_translation)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1384
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1385 def _ctcp_dequote(message):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1386 """[Internal] Dequote a message according to CTCP specifications.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1387
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1388 The function returns a list where each element can be either a
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1389 string (normal message) or a tuple of one or two strings (tagged
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1390 messages). If a tuple has only one element (ie is a singleton),
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1391 that element is the tag; otherwise the tuple has two elements: the
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1392 tag and the data.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1393
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1394 Arguments:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1395
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1396 message -- The message to be decoded.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1397 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1398
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1399 def _low_level_replace(match_obj):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1400 ch = match_obj.group(1)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1401
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1402 # If low_level_mapping doesn't have the character as key, we
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1403 # should just return the character.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1404 return _low_level_mapping.get(ch, ch)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1405
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1406 if _LOW_LEVEL_QUOTE in message:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1407 # Yup, there was a quote. Release the dequoter, man!
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1408 message = _low_level_regexp.sub(_low_level_replace, message)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1409
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1410 if _CTCP_DELIMITER not in message:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1411 return [message]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1412 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1413 # Split it into parts. (Does any IRC client actually *use*
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1414 # CTCP stacking like this?)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1415 chunks = message.split(_CTCP_DELIMITER)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1416
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1417 messages = []
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1418 i = 0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1419 while i < len(chunks)-1:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1420 # Add message if it's non-empty.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1421 if len(chunks[i]) > 0:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1422 messages.append(chunks[i])
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1423
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1424 if i < len(chunks)-2:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1425 # Aye! CTCP tagged data ahead!
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1426 messages.append(tuple(chunks[i+1].split(" ", 1)))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1427
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1428 i = i + 2
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1429
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1430 if len(chunks) % 2 == 0:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1431 # Hey, a lonely _CTCP_DELIMITER at the end! This means
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1432 # that the last chunk, including the delimiter, is a
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1433 # normal message! (This is according to the CTCP
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1434 # specification.)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1435 messages.append(_CTCP_DELIMITER + chunks[-1])
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1436
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1437 return messages
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1438
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1439 def is_channel(string):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1440 """Check if a string is a channel name.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1441
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1442 Returns true if the argument is a channel name, otherwise false.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1443 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1444 return string and string[0] in "#&+!"
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1445
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1446 def ip_numstr_to_quad(num):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1447 """Convert an IP number as an integer given in ASCII
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1448 representation (e.g. '3232235521') to an IP address string
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1449 (e.g. '192.168.0.1')."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1450 n = long(num)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1451 p = map(str, map(int, [n >> 24 & 0xFF, n >> 16 & 0xFF,
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1452 n >> 8 & 0xFF, n & 0xFF]))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1453 return ".".join(p)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1454
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1455 def ip_quad_to_numstr(quad):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1456 """Convert an IP address string (e.g. '192.168.0.1') to an IP
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1457 number as an integer given in ASCII representation
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1458 (e.g. '3232235521')."""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1459 p = map(long, quad.split("."))
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1460 s = str((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3])
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1461 if s[-1] == "L":
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1462 s = s[:-1]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1463 return s
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1464
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1465 def nm_to_n(s):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1466 """Get the nick part of a nickmask.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1467
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1468 (The source of an Event is a nickmask.)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1469 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1470 return s.split("!")[0]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1471
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1472 def nm_to_uh(s):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1473 """Get the userhost part of a nickmask.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1474
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1475 (The source of an Event is a nickmask.)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1476 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1477 return s.split("!")[1]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1478
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1479 def nm_to_h(s):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1480 """Get the host part of a nickmask.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1481
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1482 (The source of an Event is a nickmask.)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1483 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1484 return s.split("@")[1]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1485
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1486 def nm_to_u(s):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1487 """Get the user part of a nickmask.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1488
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1489 (The source of an Event is a nickmask.)
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1490 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1491 s = s.split("!")[1]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1492 return s.split("@")[0]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1493
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1494 def parse_nick_modes(mode_string):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1495 """Parse a nick mode string.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1496
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1497 The function returns a list of lists with three members: sign,
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1498 mode and argument. The sign is \"+\" or \"-\". The argument is
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1499 always None.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1500
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1501 Example:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1502
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1503 >>> irclib.parse_nick_modes(\"+ab-c\")
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1504 [['+', 'a', None], ['+', 'b', None], ['-', 'c', None]]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1505 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1506
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1507 return _parse_modes(mode_string, "")
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1508
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1509 def parse_channel_modes(mode_string):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1510 """Parse a channel mode string.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1511
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1512 The function returns a list of lists with three members: sign,
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1513 mode and argument. The sign is \"+\" or \"-\". The argument is
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1514 None if mode isn't one of \"b\", \"k\", \"l\", \"v\" or \"o\".
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1515
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1516 Example:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1517
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1518 >>> irclib.parse_channel_modes(\"+ab-c foo\")
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1519 [['+', 'a', None], ['+', 'b', 'foo'], ['-', 'c', None]]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1520 """
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1521
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1522 return _parse_modes(mode_string, "bklvo")
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1523
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1524 def _parse_modes(mode_string, unary_modes=""):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1525 """[Internal]"""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1526 modes = []
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1527 arg_count = 0
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1528
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1529 # State variable.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1530 sign = ""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1531
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1532 a = mode_string.split()
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1533 if len(a) == 0:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1534 return []
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1535 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1536 mode_part, args = a[0], a[1:]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1537
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1538 if mode_part[0] not in "+-":
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1539 return []
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1540 for ch in mode_part:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1541 if ch in "+-":
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1542 sign = ch
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1543 elif ch == " ":
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1544 collecting_arguments = 1
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1545 elif ch in unary_modes:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1546 if len(args) >= arg_count + 1:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1547 modes.append([sign, ch, args[arg_count]])
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1548 arg_count = arg_count + 1
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1549 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1550 modes.append([sign, ch, None])
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1551 else:
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1552 modes.append([sign, ch, None])
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1553 return modes
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1554
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1555 def _ping_ponger(connection, event):
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1556 """[Internal]"""
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1557 connection.pong(event.target())
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1558
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1559 # Numeric table mostly stolen from the Perl IRC module (Net::IRC).
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1560 numeric_events = {
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1561 "001": "welcome",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1562 "002": "yourhost",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1563 "003": "created",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1564 "004": "myinfo",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1565 "005": "featurelist", # XXX
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1566 "200": "tracelink",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1567 "201": "traceconnecting",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1568 "202": "tracehandshake",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1569 "203": "traceunknown",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1570 "204": "traceoperator",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1571 "205": "traceuser",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1572 "206": "traceserver",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1573 "207": "traceservice",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1574 "208": "tracenewtype",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1575 "209": "traceclass",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1576 "210": "tracereconnect",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1577 "211": "statslinkinfo",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1578 "212": "statscommands",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1579 "213": "statscline",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1580 "214": "statsnline",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1581 "215": "statsiline",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1582 "216": "statskline",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1583 "217": "statsqline",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1584 "218": "statsyline",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1585 "219": "endofstats",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1586 "221": "umodeis",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1587 "231": "serviceinfo",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1588 "232": "endofservices",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1589 "233": "service",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1590 "234": "servlist",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1591 "235": "servlistend",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1592 "241": "statslline",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1593 "242": "statsuptime",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1594 "243": "statsoline",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1595 "244": "statshline",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1596 "250": "luserconns",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1597 "251": "luserclient",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1598 "252": "luserop",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1599 "253": "luserunknown",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1600 "254": "luserchannels",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1601 "255": "luserme",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1602 "256": "adminme",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1603 "257": "adminloc1",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1604 "258": "adminloc2",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1605 "259": "adminemail",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1606 "261": "tracelog",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1607 "262": "endoftrace",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1608 "263": "tryagain",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1609 "265": "n_local",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1610 "266": "n_global",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1611 "300": "none",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1612 "301": "away",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1613 "302": "userhost",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1614 "303": "ison",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1615 "305": "unaway",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1616 "306": "nowaway",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1617 "311": "whoisuser",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1618 "312": "whoisserver",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1619 "313": "whoisoperator",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1620 "314": "whowasuser",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1621 "315": "endofwho",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1622 "316": "whoischanop",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1623 "317": "whoisidle",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1624 "318": "endofwhois",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1625 "319": "whoischannels",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1626 "321": "liststart",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1627 "322": "list",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1628 "323": "listend",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1629 "324": "channelmodeis",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1630 "329": "channelcreate",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1631 "331": "notopic",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1632 "332": "currenttopic",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1633 "333": "topicinfo",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1634 "341": "inviting",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1635 "342": "summoning",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1636 "346": "invitelist",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1637 "347": "endofinvitelist",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1638 "348": "exceptlist",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1639 "349": "endofexceptlist",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1640 "351": "version",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1641 "352": "whoreply",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1642 "353": "namreply",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1643 "361": "killdone",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1644 "362": "closing",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1645 "363": "closeend",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1646 "364": "links",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1647 "365": "endoflinks",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1648 "366": "endofnames",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1649 "367": "banlist",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1650 "368": "endofbanlist",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1651 "369": "endofwhowas",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1652 "371": "info",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1653 "372": "motd",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1654 "373": "infostart",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1655 "374": "endofinfo",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1656 "375": "motdstart",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1657 "376": "endofmotd",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1658 "377": "motd2", # 1997-10-16 -- tkil
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1659 "381": "youreoper",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1660 "382": "rehashing",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1661 "384": "myportis",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1662 "391": "time",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1663 "392": "usersstart",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1664 "393": "users",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1665 "394": "endofusers",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1666 "395": "nousers",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1667 "401": "nosuchnick",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1668 "402": "nosuchserver",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1669 "403": "nosuchchannel",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1670 "404": "cannotsendtochan",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1671 "405": "toomanychannels",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1672 "406": "wasnosuchnick",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1673 "407": "toomanytargets",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1674 "409": "noorigin",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1675 "411": "norecipient",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1676 "412": "notexttosend",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1677 "413": "notoplevel",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1678 "414": "wildtoplevel",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1679 "421": "unknowncommand",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1680 "422": "nomotd",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1681 "423": "noadmininfo",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1682 "424": "fileerror",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1683 "431": "nonicknamegiven",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1684 "432": "erroneusnickname", # Thiss iz how its speld in thee RFC.
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1685 "433": "nicknameinuse",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1686 "436": "nickcollision",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1687 "437": "unavailresource", # "Nick temporally unavailable"
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1688 "441": "usernotinchannel",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1689 "442": "notonchannel",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1690 "443": "useronchannel",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1691 "444": "nologin",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1692 "445": "summondisabled",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1693 "446": "usersdisabled",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1694 "451": "notregistered",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1695 "461": "needmoreparams",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1696 "462": "alreadyregistered",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1697 "463": "nopermforhost",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1698 "464": "passwdmismatch",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1699 "465": "yourebannedcreep", # I love this one...
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1700 "466": "youwillbebanned",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1701 "467": "keyset",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1702 "471": "channelisfull",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1703 "472": "unknownmode",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1704 "473": "inviteonlychan",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1705 "474": "bannedfromchan",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1706 "475": "badchannelkey",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1707 "476": "badchanmask",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1708 "477": "nochanmodes", # "Channel doesn't support modes"
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1709 "478": "banlistfull",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1710 "481": "noprivileges",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1711 "482": "chanoprivsneeded",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1712 "483": "cantkillserver",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1713 "484": "restricted", # Connection is restricted
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1714 "485": "uniqopprivsneeded",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1715 "491": "nooperhost",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1716 "492": "noservicehost",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1717 "501": "umodeunknownflag",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1718 "502": "usersdontmatch",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1719 }
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1720
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1721 generated_events = [
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1722 # Generated events
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1723 "dcc_connect",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1724 "dcc_disconnect",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1725 "dccmsg",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1726 "disconnect",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1727 "ctcp",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1728 "ctcpreply",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1729 ]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1730
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1731 protocol_events = [
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1732 # IRC protocol events
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1733 "error",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1734 "join",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1735 "kick",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1736 "mode",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1737 "part",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1738 "ping",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1739 "privmsg",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1740 "privnotice",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1741 "pubmsg",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1742 "pubnotice",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1743 "quit",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1744 "invite",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1745 "pong",
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1746 ]
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1747
4c842d23d4ce Initial commit, version 0.1
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1748 all_events = generated_events + protocol_events + numeric_events.values()