irc.py

Sat, 08 Aug 2015 14:17:30 +0300

author
Teemu Piippo <tsapii@utu.fi>
date
Sat, 08 Aug 2015 14:17:30 +0300
changeset 149
1759c15cd0ca
parent 146
c17b82b1f573
child 152
1b734faab67a
permissions
-rw-r--r--

Added ability to define commands into the manifest

124
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
1 '''
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
2 Copyright 2014-2015 Teemu Piippo
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
3 All rights reserved.
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
4
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
5 Redistribution and use in source and binary forms, with or without
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
6 modification, are permitted provided that the following conditions
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
7 are met:
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
8
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
9 1. Redistributions of source code must retain the above copyright
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
10 notice, this list of conditions and the following disclaimer.
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
11 2. Redistributions in binary form must reproduce the above copyright
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
12 notice, this list of conditions and the following disclaimer in the
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
13 documentation and/or other materials provided with the distribution.
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
14 3. The name of the author may not be used to endorse or promote products
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
15 derived from this software without specific prior written permission.
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
16
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
17 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
18 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
19 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
20 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
21 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
22 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
27 '''
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
28
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
29 from __future__ import print_function
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 import asyncore
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 import socket
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 import sys
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 import re
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 import modulecore as ModuleCore
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 import traceback
132
a22c50f52a23 lots of new stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
36 import time
143
d86a81540a71 Include timestamp in console outputs
Teemu Piippo <tsapii@utu.fi>
parents: 140
diff changeset
37 import datetime
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 from configfile import Config
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 import bt as Bt
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 import hgpoll as HgPoll
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 CLIF_CONNECTED = (1 << 1)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43
119
Teemu Piippo <crimsondusk64@gmail.com>
parents: 118
diff changeset
44 CtcpChar = '\001'
Teemu Piippo <crimsondusk64@gmail.com>
parents: 118
diff changeset
45 BoldChar = '\002'
Teemu Piippo <crimsondusk64@gmail.com>
parents: 118
diff changeset
46 ColorChar = '\003'
Teemu Piippo <crimsondusk64@gmail.com>
parents: 118
diff changeset
47
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 all_clients = []
132
a22c50f52a23 lots of new stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
49 ClientsByName = {}
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 class RestartError (Exception):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 def __init__ (self, value):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 self.message = value
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 def __str__ (self):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 return self.message
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56
143
d86a81540a71 Include timestamp in console outputs
Teemu Piippo <tsapii@utu.fi>
parents: 140
diff changeset
57 def get_timestamp():
d86a81540a71 Include timestamp in console outputs
Teemu Piippo <tsapii@utu.fi>
parents: 140
diff changeset
58 return datetime.datetime.now().strftime ('%a %d %b %H:%M:%S')
d86a81540a71 Include timestamp in console outputs
Teemu Piippo <tsapii@utu.fi>
parents: 140
diff changeset
59
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 #
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 # Prints a line to log channel(s)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 #
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 def broadcast (line):
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
64 print (line)
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
65
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 for client in all_clients:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 if not client.flags & CLIF_CONNECTED:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 continue
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 for channel in client.channels:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 if channel.get_value ('logchannel', default=False):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 client.write ("PRIVMSG %s :%s" % (channel.get_value ('name'), line))
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 class logical_exception (Exception):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 def __init__ (self, value):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 self.value = value
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 def __str__ (self):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 return self.value
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79
118
dbf49689af0d - added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
80 def get_client (name):
dbf49689af0d - added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
81 for client in all_clients:
dbf49689af0d - added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
82 if client.name == name:
dbf49689af0d - added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
83 return client
dbf49689af0d - added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
84
dbf49689af0d - added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
85 raise ValueError ('no such client %s' % name)
dbf49689af0d - added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
86
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 #
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 # Main IRC client class
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 #
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 class irc_client (asyncore.dispatcher):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 def __init__ (self, cfg, flags):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 global all_clients
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 self.name = cfg.get_value ('name')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 self.host = cfg.get_value ('address')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 self.port = cfg.get_value ('port', default=6667)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 self.password = cfg.get_value ('password', default='')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 self.channels = cfg.get_nodelist ('channels')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 self.flags = flags
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 self.send_buffer = []
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 self.umode = cfg.get_value ('umode', default='')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 self.cfg = cfg
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 self.desired_name = Config.get_value ('nickname', default='cobalt')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 self.mynick = self.desired_name
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 self.verbose = Config.get_value ('verbose', default=False)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 self.commandprefix = Config.get_value ('commandprefix', default='.')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 all_clients.append (self)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 asyncore.dispatcher.__init__ (self)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
109 print ("[%s] Connecting to [%s] %s:%d..." % \
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
110 (get_timestamp(), self.name, self.host, self.port))
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 self.connect ((self.host, self.port))
132
a22c50f52a23 lots of new stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
112 ClientsByName[self.name] = self
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 def register_to_irc (self):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 ident = Config.get_value ('ident', default='cobalt')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 gecos = Config.get_value ('gecos', default='cobalt')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 self.write ("PASS %s" % self.password)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 self.write ("USER %s * * :%s" % (ident, gecos))
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 self.write ("NICK %s" % self.mynick)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 def handle_connect (self):
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
122 print ("[%s] Connected to [%s] %s:%d" % (get_timestamp(), self.name, self.host, self.port))
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 self.register_to_irc()
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 def write (self, utfdata):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126 try:
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
127 if sys.version_info < (3, 0):
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
128 self.send_buffer.append (utfdata.decode("utf-8","ignore").encode("ascii","ignore"))
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
129 else:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
130 self.send_buffer.append (utfdata)
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 except UnicodeEncodeError:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 pass
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 def handle_close (self):
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
135 print ("[%s] Connection to [%s] %s:%d terminated." %
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
136 (get_timestamp(), self.name, self.host, self.port))
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 self.close()
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 def handle_write (self):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 self.send_all_now()
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 def readable (self):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 return True
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145 def writable (self):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146 return len (self.send_buffer) > 0
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 def send_all_now (self):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149 for line in self.send_buffer:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 if self.verbose:
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
151 print ("[%s] [%s] <- %s" % (get_timestamp(), self.name, line))
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
152
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
153 if sys.version_info >= (3, 0):
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
154 self.send (bytes (line + '\n', 'UTF-8'))
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
155 else:
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
156 self.send (line + '\n')
132
a22c50f52a23 lots of new stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 124
diff changeset
157 time.sleep (0.25)
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 self.send_buffer = []
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 def handle_read (self):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 lines = self.recv (4096).splitlines()
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
162 for line in lines:
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163 try:
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
164 line = line.decode ('utf-8', 'ignore')
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
165
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
166 if sys.version_info < (3, 0):
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
167 line = line.encode ('ascii', 'ignore')
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 except UnicodeDecodeError:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169 continue
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 if self.verbose:
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
172 print ("[%s] [%s] -> %s" % (get_timestamp(), self.name, line))
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
174 if line[:len('PING :')] == ('PING :'):
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
175 self.write ("PONG :%s" % line[len('PING :'):])
123
aeb0d0788869 - added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents: 120
diff changeset
176 self.send_all_now() # pings must be responded to immediately!
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177 else:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 words = line.split(" ")
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 if len(words) >= 2:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 if words[1] == "001":
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 self.flags |= CLIF_CONNECTED
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 umode = self.cfg.get_value ('umode', '')
92
da291d9426ea - first implementation of REST
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
184
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185 if umode != '':
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186 self.write ('MODE %s %s' % (self.mynick, self.cfg.get_value ('umode', '')))
120
9880bb697149 - added doomseeker support, fixed up mod_bridge, now shortens new commit links with bit.ly
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
187
9880bb697149 - added doomseeker support, fixed up mod_bridge, now shortens new commit links with bit.ly
Teemu Piippo <crimsondusk64@gmail.com>
parents: 119
diff changeset
188 for channel in self.channels:
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
189 self.write ("JOIN %s %s" %
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
190 (channel.get_value ('name'),
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
191 channel.get_value ('password', default='')))
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192 elif words[1] == "PRIVMSG":
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 self.handle_privmsg (line)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194 elif words[1] == 'QUIT':
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195 rex = re.compile (r'^:([^!]+)!([^@]+)@([^ ]+) QUIT')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196 match = rex.match (line)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
197
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
198 # Try reclaim our nickname if possible
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
199 if match and match.group(1) == self.desired_name:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
200 self.mynick = self.desired_name
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
201 self.write ("NICK %s" % self.mynick)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
202 elif words[1] == "433":
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203 #:irc.localhost 433 * cobalt :Nickname is already in use.
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204 self.mynick += self.cfg.get_value ('conflictsuffix', default='`')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205 self.write ("NICK " + self.mynick)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207 # Check for new issues on the bugtracker
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
208 Bt.poll()
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
209
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210 # Check for new commits in the repositories
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
211 HgPoll.poll()
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
212
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
213 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214 #
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215 # Handle a PRIVMSG line from the IRC server
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
216 #
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
217 def handle_privmsg (self, line):
112
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
218 rex = re.compile (r'^:([^!]+)!([^@]+)@([^ ]+) PRIVMSG ([^ ]+) :(.*)$')
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
219 match = rex.match (line)
92
da291d9426ea - first implementation of REST
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
220
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221 if not match:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
222 broadcast ("Recieved bad PRIVMSG: %s" % line)
112
cdafc1a0544e - stuff!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 94
diff changeset
223 return
92
da291d9426ea - first implementation of REST
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
224
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
225 sender = match.group (1)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
226 user = match.group (2)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
227 host = match.group (3)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
228 channel = match.group (4)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229 message = match.group (5)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230 replyto = channel if channel != self.mynick else sender
92
da291d9426ea - first implementation of REST
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
231
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232 # Check for command.
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
233 if len(message) >= 2 and message[0] == self.commandprefix and message[1] != self.commandprefix:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
234 stuff = message[1:].split(' ')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
235 command = stuff[0]
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236 args = stuff[1:]
118
dbf49689af0d - added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
237 self.handle_command (sender, user, host, channel, replyto, command, args, message)
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
238 return
92
da291d9426ea - first implementation of REST
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
239
118
dbf49689af0d - added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
240 if channel != self.mynick:
dbf49689af0d - added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
241 ModuleCore.call_hook (bot=self, hookname='chanmsg', channel=channel, sender=sender,
dbf49689af0d - added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
242 ident=user, host=host, message=message, replyto=replyto)
dbf49689af0d - added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
243 else:
dbf49689af0d - added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
244 ModuleCore.call_hook (bot=self, hookname='querymsg', sender=sender, ident=user,
dbf49689af0d - added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
245 host=host, message=message, replyto=replyto)
dbf49689af0d - added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
246
dbf49689af0d - added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
247 ModuleCore.call_hook (bot=self, hookname='privmsg', target=channel, sender=sender,
dbf49689af0d - added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
248 ident=user, host=host, message=message, replyto=replyto)
dbf49689af0d - added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
249
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
250 Bt.process_message (self, line, replyto)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
252 def add_irc_channel (self, channame):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
253 for channel in self.channels:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
254 if channel.get_value ('name').upper() == channame.upper():
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
255 return
92
da291d9426ea - first implementation of REST
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
256
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
257 channel = self.cfg.append_nodelist ('channels')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
258 channel.set_value ('name', channame)
76
a2fe9ba3041a - various fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
259 self.channels = self.cfg.get_nodelist ('channels')
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
260 self.write ('JOIN ' + channame)
76
a2fe9ba3041a - various fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
261 self.cfg.save()
92
da291d9426ea - first implementation of REST
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
262
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263 def remove_irc_channel (self, channame):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
264 for channel in self.channels:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
265 if channel.get_value ('name') == channame:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
266 self.channels.remove (channel)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
267 break
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
268 else:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269 return
92
da291d9426ea - first implementation of REST
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
270
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
271 self.write ('PART ' + channame)
76
a2fe9ba3041a - various fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
272 self.cfg.save()
92
da291d9426ea - first implementation of REST
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
273
118
dbf49689af0d - added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
274 def handle_command (self, sender, ident, host, target, replyto, command, args, message):
dbf49689af0d - added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
275 kvargs = {'sender': sender, 'ident': ident, 'host': host, 'target': target,
dbf49689af0d - added bridging functionality
Teemu Piippo <crimsondusk64@gmail.com>
parents: 117
diff changeset
276 'replyto': replyto, 'cmdname': command, 'message': message}
92
da291d9426ea - first implementation of REST
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
277
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
278 try:
117
6c0609395889 - added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents: 112
diff changeset
279 ModuleCore.call_command (self, **kvargs)
6c0609395889 - added a confirm system, probably useful in the future
Teemu Piippo <crimsondusk64@gmail.com>
parents: 112
diff changeset
280 return
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
281 except ModuleCore.CommandError as e:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
282 lines = str (e).split ('\n')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
283 self.privmsg (replyto, 'error: %s' % lines[0])
92
da291d9426ea - first implementation of REST
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
284
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
285 for line in lines[1:]:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
286 self.privmsg (replyto, ' ' + line)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
287 return
92
da291d9426ea - first implementation of REST
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
288
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
289 def handle_error(self):
146
c17b82b1f573 Mercurial handling major overhaul. Also get some stuff ready for Python 3
Teemu Piippo <tsapii@utu.fi>
parents: 143
diff changeset
290 raise RestartError (traceback.format_exception (*sys.exc_info()))
92
da291d9426ea - first implementation of REST
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
291
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
292 def restart(self):
81
ce5d27463356 - fixed bad RestartError construction
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
293 raise RestartError('')
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
294
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
295 def privmsg (self, channel, msg):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
296 self.write ("PRIVMSG %s :%s" % (channel, msg))
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
297
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
298 def close_connection (self, message):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
299 if self.flags & CLIF_CONNECTED:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
300 self.write ("QUIT :" + message)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
301 self.send_all_now()
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
302 self.close()
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
303
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
304 def quit_irc (self):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
305 self.close_connection ('Leaving')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
306
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
307 def exceptdie (self):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
308 self.close_connection ('Caught exception')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
309
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
310 def keyboardinterrupt (self):
92
da291d9426ea - first implementation of REST
Teemu Piippo <crimsondusk64@gmail.com>
parents: 81
diff changeset
311 self.close_connection ('KeyboardInterrupt')

mercurial