Sun, 29 Jun 2014 21:36:01 +0000
README.md edited online with Bitbucket
0 | 1 | #!/usr/bin/env python |
2 | ''' | |
3 | Copyright 2014 Santeri Piippo | |
4 | All rights reserved. | |
5 | ||
6 | Redistribution and use in source and binary forms, with or without | |
7 | modification, are permitted provided that the following conditions | |
8 | are met: | |
9 | ||
10 | 1. Redistributions of source code must retain the above copyright | |
11 | notice, this list of conditions and the following disclaimer. | |
12 | 2. Redistributions in binary form must reproduce the above copyright | |
13 | notice, this list of conditions and the following disclaimer in the | |
14 | documentation and/or other materials provided with the distribution. | |
15 | 3. The name of the author may not be used to endorse or promote products | |
16 | derived from this software without specific prior written permission. | |
17 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
19 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
20 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
21 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
23 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
27 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 | ''' | |
29 | ||
30 | import asyncore | |
31 | import socket | |
32 | import time | |
33 | import sys | |
34 | import traceback | |
35 | import re | |
36 | import json | |
2
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
37 | import urllib |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
38 | import urllib2 |
5
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
39 | import hgapi |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
40 | import os |
15
e7999383db5a
- don't crash if utf parsing yields an UnicodeDecodeError
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
41 | import suds |
0 | 42 | |
43 | try: | |
20
2603faf5f91b
- don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
44 | uid = os.geteuid() |
2603faf5f91b
- don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
45 | except: |
2603faf5f91b
- don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
46 | uid = -1 |
2603faf5f91b
- don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
47 | |
2603faf5f91b
- don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
48 | if uid == 0 and raw_input ('Do you seriously want to run cobalt as root? [y/N] ') != 'y': |
2603faf5f91b
- don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
49 | quit() |
2603faf5f91b
- don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
50 | |
2603faf5f91b
- don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
51 | print 'Loading configuration...' |
2603faf5f91b
- don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
52 | try: |
0 | 53 | with open ('cobalt.json', 'r') as fp: |
54 | g_config = json.loads (fp.read()) | |
55 | except IOError as e: | |
56 | print 'couldn\'t open cobalt.json: %s' % e | |
57 | quit() | |
58 | ||
59 | g_admins = g_config['admins'] | |
60 | g_mynick = g_config['nickname'] | |
61 | ||
2
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
62 | g_idgamesSearchURL = 'http://www.doomworld.com/idgames/api/api.php?action=search&query=%s&type=title&sort=date&out=json' |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
63 | |
0 | 64 | # |
65 | # SOAP stuff | |
66 | # | |
3
53486417a8e5
- handle the case where the mantisbt is not available
Santeri Piippo <crimsondusk64@gmail.com>
parents:
2
diff
changeset
|
67 | suds_active = False |
53486417a8e5
- handle the case where the mantisbt is not available
Santeri Piippo <crimsondusk64@gmail.com>
parents:
2
diff
changeset
|
68 | |
53486417a8e5
- handle the case where the mantisbt is not available
Santeri Piippo <crimsondusk64@gmail.com>
parents:
2
diff
changeset
|
69 | try: |
20
2603faf5f91b
- don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
70 | print 'Initializing MantisBT connection...' |
15
e7999383db5a
- don't crash if utf parsing yields an UnicodeDecodeError
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
71 | suds_import = suds.xsd.doctor.Import ('http://schemas.xmlsoap.org/soap/encoding/', 'http://schemas.xmlsoap.org/soap/encoding/') |
e7999383db5a
- don't crash if utf parsing yields an UnicodeDecodeError
Santeri Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
72 | suds_client = suds.client.Client ('https://zandronum.com/tracker/api/soap/mantisconnect.php?wsdl', plugins=[suds.xsd.doctor.ImportDoctor (suds_import)]) |
3
53486417a8e5
- handle the case where the mantisbt is not available
Santeri Piippo <crimsondusk64@gmail.com>
parents:
2
diff
changeset
|
73 | suds_active = True |
20
2603faf5f91b
- don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
74 | except Exception as e: |
2603faf5f91b
- don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
75 | print 'Failed to establish MantisBT connection: ' + `e` |
3
53486417a8e5
- handle the case where the mantisbt is not available
Santeri Piippo <crimsondusk64@gmail.com>
parents:
2
diff
changeset
|
76 | pass |
0 | 77 | |
12
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
78 | btannounce_active = False |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
79 | btannounce_timeout = 0 |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
80 | |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
81 | def save_config(): |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
82 | with open ('cobalt.json', 'w') as fp: |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
83 | json.dump (g_config, fp, sort_keys = True, indent = 4) |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
84 | |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
85 | def cfg (key, default): |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
86 | if not hasattr (g_config, key): |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
87 | g_config[key] = default |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
88 | save_config() |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
89 | return default |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
90 | return g_config[key] |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
91 | |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
92 | def bt_updatechecktimeout(): |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
93 | global btannounce_timeout |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
94 | btannounce_timeout = time.time() + (cfg ('btlatest_checkinterval', 5) * 60) |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
95 | |
19
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
96 | def bool_from_string (value): |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
97 | if value != 'true' and value != 'false': |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
98 | raise logical_exception ('expected true or false for value') |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
99 | return True if value == 'true' else False |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
100 | |
12
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
101 | if suds_active: |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
102 | try: |
20
2603faf5f91b
- don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
103 | sys.stdout.write ('Retrieving latest tracker ticket... ') |
13
4da122a2f79f
- don't need that '- 1' anymore
Santeri Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
104 | btannounce_id = suds_client.service.mc_issue_get_biggest_id (g_config['trackeruser'], g_config ['trackerpassword'], 0) |
12
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
105 | btannounce_active = True |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
106 | bt_updatechecktimeout() |
20
2603faf5f91b
- don't run as root without asking first, added more startup messages
Santeri Piippo <crimsondusk64@gmail.com>
parents:
19
diff
changeset
|
107 | print btannounce_id |
12
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
108 | except Exception as e: |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
109 | pass |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
110 | |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
111 | def bt_getissue(ticket): |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
112 | global suds_client |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
113 | global g_config |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
114 | return suds_client.service.mc_issue_get (g_config['trackeruser'], g_config['trackerpassword'], ticket) |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
115 | |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
116 | def bt_checklatest(): |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
117 | global btannounce_timeout |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
118 | global btannounce_id |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
119 | |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
120 | if time.time() >= btannounce_timeout: |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
121 | bt_updatechecktimeout() |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
122 | newid = btannounce_id |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
123 | try: |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
124 | newid = suds_client.service.mc_issue_get_biggest_id (g_config['trackeruser'], g_config ['trackerpassword'], 0) |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
125 | except Exception as e: |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
126 | pass |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
127 | |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
128 | while newid > btannounce_id: |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
129 | try: |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
130 | btannounce_id += 1 |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
131 | data = bt_getissue (btannounce_id) |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
132 | |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
133 | for client in g_clients: |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
134 | client.announce_ticket (data) |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
135 | except Exception as e: |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
136 | pass |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
137 | |
0 | 138 | # |
139 | # irc_client flags | |
140 | # | |
141 | CLIF_CONNECTED = (1 << 1) | |
142 | ||
143 | # | |
144 | # List of all clients | |
145 | # | |
146 | g_clients = [] | |
147 | ||
148 | class channel (object): | |
149 | name = "" | |
150 | password = "" | |
151 | ||
152 | def __init__ (self, name): | |
153 | self.name = name | |
154 | ||
155 | # | |
19
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
156 | # Prints a line to log channel(s) |
0 | 157 | # |
19
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
158 | def chanlog (line): |
0 | 159 | for client in g_clients: |
19
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
160 | if not client.flags & CLIF_CONNECTED: |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
161 | continue |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
162 | |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
163 | for channel in client.channels: |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
164 | if channel['logchannel']: |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
165 | client.write ("PRIVMSG %s :%s" % (channel['name'], line)) |
0 | 166 | |
167 | # | |
168 | # Exception handling | |
169 | # | |
170 | def handle_exception(excType, excValue, trace): | |
171 | excepterm (traceback.format_exception(excType, excValue, trace)) | |
172 | ||
173 | def excepterm(data): | |
174 | for segment in data: | |
175 | for line in segment.splitlines(): | |
176 | print line | |
19
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
177 | chanlog (line) |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
178 | |
0 | 179 | for client in g_clients: |
5
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
180 | if len(data) > 0: |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
181 | client.exceptdie() |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
182 | else: |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
183 | client.quit_irc() |
19
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
184 | |
5
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
185 | restart_self() |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
186 | #quit() |
0 | 187 | |
188 | sys.excepthook = handle_exception | |
189 | ||
1
29c7e9d13a30
- fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
190 | def check_admin (sender, ident, host, command): |
16
6672cecf3ed1
- don't crash if unicode parsing fails, don't require nickname for admin masks
Santeri Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
191 | if not "%s@%s" % (ident, host) in g_admins: |
1
29c7e9d13a30
- fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
192 | raise logical_exception (".%s requires admin access" % command) |
0 | 193 | |
1
29c7e9d13a30
- fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
194 | class logical_exception (Exception): |
29c7e9d13a30
- fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
195 | def __init__ (self, value): |
29c7e9d13a30
- fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
196 | self.value = value |
29c7e9d13a30
- fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
197 | def __str__ (self): |
29c7e9d13a30
- fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
198 | return self.value |
29c7e9d13a30
- fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
199 | |
5
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
200 | # from http://www.daniweb.com/software-development/python/code/260268/restart-your-python-program |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
201 | def restart_self(): |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
202 | python = sys.executable |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
203 | os.execl (python, python, * sys.argv) |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
204 | |
1
29c7e9d13a30
- fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
205 | # |
29c7e9d13a30
- fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
206 | # Main IRC client class |
29c7e9d13a30
- fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
207 | # |
0 | 208 | class irc_client (asyncore.dispatcher): |
209 | def __init__ (self, cfg, flags): | |
210 | self.name = cfg['name'] | |
211 | self.host = cfg['address'] | |
212 | self.port = cfg['port'] | |
213 | self.password = cfg['password'] if 'password' in cfg else '' | |
214 | self.channels = cfg['channels'] | |
215 | self.flags = flags | |
216 | self.send_buffer = list() | |
217 | self.umode = cfg['umode'] if 'umode' in cfg else '' | |
218 | self.cfg = cfg | |
219 | self.mynick = '' | |
12
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
220 | self.verbose = g_config['verbose'] if 'verbose' in g_config else False |
11
90851b22ab88
- gddmnt, python. you and your type system
Santeri Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
221 | self.commandprefix = g_config['commandprefix'][0] if 'commandprefix' in g_config else '.' |
8
dd467db4b18e
- made conflictsuffix configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
222 | |
19
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
223 | for channel in self.channels: |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
224 | if not 'logchannel' in channel: |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
225 | channel['logchannel'] = False |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
226 | |
8
dd467db4b18e
- made conflictsuffix configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
227 | if not 'conflictsuffix' in self.cfg: |
dd467db4b18e
- made conflictsuffix configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
228 | self.cfg['conflictsuffix'] = '`' |
dd467db4b18e
- made conflictsuffix configurable
Santeri Piippo <crimsondusk64@gmail.com>
parents:
7
diff
changeset
|
229 | |
7
438dc247ceb9
- handle nickname shenanigans: handle 433 message and try reclaim nickname if someone who has taken it (possibly our own ghost) disconnected
Santeri Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
230 | self.desired_name = self.cfg['nickname'] if 'nickname' in self.cfg else g_config['nickname'] |
0 | 231 | g_clients.append (self) |
232 | asyncore.dispatcher.__init__ (self) | |
233 | self.create_socket (socket.AF_INET, socket.SOCK_STREAM) | |
234 | self.connect ((self.host, self.port)) | |
235 | ||
7
438dc247ceb9
- handle nickname shenanigans: handle 433 message and try reclaim nickname if someone who has taken it (possibly our own ghost) disconnected
Santeri Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
236 | def register_to_irc (self): |
0 | 237 | ident = self.cfg['ident'] if 'ident' in self.cfg else g_config['ident'] |
238 | gecos = self.cfg['gecos'] if 'gecos' in self.cfg else g_config['gecos'] | |
239 | if 'password' in self.cfg: | |
240 | self.write ("PASS %s" % self.cfg['password']) | |
241 | self.write ("USER %s * * :%s" % (ident, gecos)) | |
7
438dc247ceb9
- handle nickname shenanigans: handle 433 message and try reclaim nickname if someone who has taken it (possibly our own ghost) disconnected
Santeri Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
242 | self.write ("NICK %s" % self.mynick) |
438dc247ceb9
- handle nickname shenanigans: handle 433 message and try reclaim nickname if someone who has taken it (possibly our own ghost) disconnected
Santeri Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
243 | |
438dc247ceb9
- handle nickname shenanigans: handle 433 message and try reclaim nickname if someone who has taken it (possibly our own ghost) disconnected
Santeri Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
244 | def handle_connect (self): |
438dc247ceb9
- handle nickname shenanigans: handle 433 message and try reclaim nickname if someone who has taken it (possibly our own ghost) disconnected
Santeri Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
245 | self.mynick = self.desired_name |
438dc247ceb9
- handle nickname shenanigans: handle 433 message and try reclaim nickname if someone who has taken it (possibly our own ghost) disconnected
Santeri Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
246 | print "Connected to [%s] %s:%d" % (self.name, self.host, self.port) |
438dc247ceb9
- handle nickname shenanigans: handle 433 message and try reclaim nickname if someone who has taken it (possibly our own ghost) disconnected
Santeri Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
247 | self.register_to_irc() |
0 | 248 | |
17
f604687dd35b
- don't try to send stuff we cannot convert to ascii.. I don't like it but it's better than a crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
249 | def write (self, utfdata): |
f604687dd35b
- don't try to send stuff we cannot convert to ascii.. I don't like it but it's better than a crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
250 | try: |
f604687dd35b
- don't try to send stuff we cannot convert to ascii.. I don't like it but it's better than a crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
251 | self.send_buffer.append ("%s" % utfdata.decode("utf-8","ignore").encode("ascii","ignore")) |
f604687dd35b
- don't try to send stuff we cannot convert to ascii.. I don't like it but it's better than a crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
252 | except UnicodeEncodeError: |
f604687dd35b
- don't try to send stuff we cannot convert to ascii.. I don't like it but it's better than a crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
253 | pass |
0 | 254 | |
255 | def handle_close (self): | |
256 | print "Connection to [%s] %s:%d terminated." % (self.name, self.host, self.port) | |
257 | self.close() | |
258 | ||
259 | def handle_write (self): | |
260 | self.send_all_now() | |
261 | ||
262 | def readable (self): | |
263 | return True | |
264 | ||
265 | def writable (self): | |
266 | return len (self.send_buffer) > 0 | |
267 | ||
268 | def send_all_now (self): | |
269 | for line in self.send_buffer: | |
9
0604f6b9f781
- added verbosity setting
Santeri Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
270 | if self.verbose: |
0604f6b9f781
- added verbosity setting
Santeri Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
271 | print "[%s] <- %s" % (self.name, line) |
0 | 272 | self.send ("%s\n" % line) |
273 | self.send_buffer = [] | |
274 | ||
275 | def handle_read (self): | |
276 | lines = self.recv (4096).splitlines() | |
2
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
277 | for utfline in lines: |
16
6672cecf3ed1
- don't crash if unicode parsing fails, don't require nickname for admin masks
Santeri Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
278 | try: |
17
f604687dd35b
- don't try to send stuff we cannot convert to ascii.. I don't like it but it's better than a crash
Santeri Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
279 | line = utfline.decode("utf-8","ignore").encode("ascii","ignore") |
16
6672cecf3ed1
- don't crash if unicode parsing fails, don't require nickname for admin masks
Santeri Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
280 | except UnicodeDecodeError: |
6672cecf3ed1
- don't crash if unicode parsing fails, don't require nickname for admin masks
Santeri Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
281 | continue |
6672cecf3ed1
- don't crash if unicode parsing fails, don't require nickname for admin masks
Santeri Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
282 | |
9
0604f6b9f781
- added verbosity setting
Santeri Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
283 | if self.verbose: |
0604f6b9f781
- added verbosity setting
Santeri Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
284 | print "[%s] -> %s" % (self.name, line) |
0 | 285 | |
286 | if line.startswith ("PING :"): | |
287 | self.write ("PONG :%s" % line[6:]) | |
14
558379fd6d6a
- heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
288 | else: |
558379fd6d6a
- heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
289 | words = line.split(" ") |
558379fd6d6a
- heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
290 | if len(words) >= 2: |
558379fd6d6a
- heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
291 | if words[1] == "001": |
558379fd6d6a
- heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
292 | self.flags |= CLIF_CONNECTED |
0 | 293 | |
14
558379fd6d6a
- heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
294 | for channel in self.cfg['channels']: |
558379fd6d6a
- heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
295 | self.write ("JOIN %s %s" % (channel['name'], channel['password'] if 'password' in channel else '')) |
0 | 296 | |
14
558379fd6d6a
- heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
297 | if 'umode' in self.cfg: |
558379fd6d6a
- heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
298 | self.write ('MODE %s %s' % (self.mynick, self.cfg['umode'])) |
558379fd6d6a
- heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
299 | elif words[1] == "PRIVMSG": |
558379fd6d6a
- heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
300 | self.handle_privmsg (line) |
558379fd6d6a
- heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
301 | elif words[1] == 'QUIT': |
558379fd6d6a
- heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
302 | rex = re.compile (r'^:([^!]+)!([^@]+)@([^ ]+) QUIT') |
558379fd6d6a
- heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
303 | match = rex.match (line) |
0 | 304 | |
14
558379fd6d6a
- heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
305 | # Try reclaim our nickname if possible |
558379fd6d6a
- heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
306 | if match and match.group(1) == self.desired_name: |
558379fd6d6a
- heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
307 | self.mynick = self.desired_name |
558379fd6d6a
- heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
308 | self.write ("NICK %s" % self.mynick) |
558379fd6d6a
- heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
309 | elif words[1] == "433": |
558379fd6d6a
- heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
310 | #:irc.localhost 433 * cobalt :Nickname is already in use. |
558379fd6d6a
- heartbeat the issue announcer even if we just get a ping
Santeri Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
311 | self.mynick = '%s%s' % (self.mynick, self.cfg['conflictsuffix']) |
7
438dc247ceb9
- handle nickname shenanigans: handle 433 message and try reclaim nickname if someone who has taken it (possibly our own ghost) disconnected
Santeri Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
312 | self.write ("NICK %s" % self.mynick) |
0 | 313 | |
12
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
314 | # Check for new issues on the bugtracker |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
315 | bt_checklatest() |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
316 | |
5
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
317 | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
318 | # |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
319 | # Handle a PRIVMSG line from the IRC server |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
320 | # |
0 | 321 | def handle_privmsg (self, line): |
322 | rex = re.compile (r'^:([^!]+)!([^@]+)@([^ ]+) PRIVMSG ([^ ]+) :(.+)$') | |
323 | match = rex.match (line) | |
324 | if match: | |
325 | sender = match.group (1) | |
326 | user = match.group (2) | |
327 | host = match.group (3) | |
328 | channel = match.group (4) | |
329 | message = match.group (5) | |
330 | replyto = channel if channel != g_mynick else sender | |
331 | ||
332 | # Check for tracker url in the message | |
333 | http_regex = re.compile (r'.*http(s?)://%s/view\.php\?id=([0-9]+).*' % g_config['trackerurl']) | |
334 | http_match = http_regex.match (line) | |
335 | ||
336 | # Check for command. | |
10
1b726db7b0ec
- respect the commandprefix option
Santeri Piippo <crimsondusk64@gmail.com>
parents:
9
diff
changeset
|
337 | if len(message) >= 2 and message[0] == self.commandprefix and message[1] != self.commandprefix: |
0 | 338 | stuff = message[1:].split(' ') |
339 | command = stuff[0] | |
340 | args = stuff[1:] | |
341 | try: | |
1
29c7e9d13a30
- fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
342 | self.handle_command (sender, user, host, replyto, command, args) |
21
8c389f46a056
- handle hg errors better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
343 | except logical_exception as e: |
8c389f46a056
- handle hg errors better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
344 | for line in e.value.split ('\n'): |
8c389f46a056
- handle hg errors better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
345 | if len(line) > 0: |
8c389f46a056
- handle hg errors better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
346 | self.privmsg (replyto, "error: %s" % line) |
0 | 347 | elif http_match: |
348 | self.get_ticket_data (replyto, http_match.group (2), False) | |
349 | else: | |
19
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
350 | chanlog ("Recieved bad PRIVMSG: %s" % line) |
0 | 351 | |
5
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
352 | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
353 | # |
12
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
354 | # Get the URL for a specified ticket |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
355 | # |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
356 | def get_ticket_url (self, ticket): |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
357 | return 'https://%s/view.php?id=%s' % (g_config['trackerurl'], ticket) |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
358 | |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
359 | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
360 | # |
5
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
361 | # Retrieve a ticket from mantisbt |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
362 | # |
0 | 363 | def get_ticket_data (self, replyto, ticket, withlink): |
3
53486417a8e5
- handle the case where the mantisbt is not available
Santeri Piippo <crimsondusk64@gmail.com>
parents:
2
diff
changeset
|
364 | if suds_active == False: |
53486417a8e5
- handle the case where the mantisbt is not available
Santeri Piippo <crimsondusk64@gmail.com>
parents:
2
diff
changeset
|
365 | return |
53486417a8e5
- handle the case where the mantisbt is not available
Santeri Piippo <crimsondusk64@gmail.com>
parents:
2
diff
changeset
|
366 | |
0 | 367 | data = {} |
368 | try: | |
12
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
369 | data = bt_getissue (ticket) |
0 | 370 | except Exception, e: |
371 | self.privmsg (replyto, "Failed to get info for issue %s: %s" % (ticket, `e`)) | |
372 | ||
373 | if data: | |
374 | self.privmsg (replyto, "Issue %s: %s: Reporter: %s, assigned to: %s, status: %s (%s)" % \ | |
375 | (ticket, \ | |
376 | data.summary, \ | |
4
bd9508f8a10f
- don't crash if ticket data doesn't have a reporter name (can happen if the reporter is banned)
Santeri Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
377 | data.reporter.name if hasattr (data.reporter, 'name') else "<unknown>", \ |
0 | 378 | data.handler.name if hasattr (data, 'handler') else "nobody", \ |
379 | data.status.name, \ | |
380 | data.resolution.name)) | |
381 | ||
382 | if withlink: | |
12
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
383 | self.privmsg (replyto, "Read all about it here: " + self.get_ticket_url (ticket)) |
0 | 384 | |
5
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
385 | # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
386 | # |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
387 | # Process an IRC command |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
388 | # |
1
29c7e9d13a30
- fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
389 | def handle_command (self, sender, ident, host, replyto, command, args): |
0 | 390 | if command == "raw": |
1
29c7e9d13a30
- fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
391 | check_admin (sender, ident, host, command) |
0 | 392 | self.write (" ".join (args)) |
393 | elif command == "msg": | |
1
29c7e9d13a30
- fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
394 | check_admin (sender, ident, host, command) |
0 | 395 | if len(args) < 2: |
1
29c7e9d13a30
- fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
396 | raise logical_exception ("usage: .%s <target> <message...>" % command) |
0 | 397 | self.privmsg (args[0], " ".join (args[1:])) |
2
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
398 | elif command == 'ticket': |
0 | 399 | if len(args) != 1: |
1
29c7e9d13a30
- fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
400 | raise logical_exception ("usage: .%s <ticket>" % command) |
0 | 401 | self.get_ticket_data (replyto, args[0], True) |
12
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
402 | elif command == 'testannounce': |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
403 | check_admin (sender, ident, host, command) |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
404 | if len(args) != 1: |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
405 | raise logical_exception ("usage: .%s <ticket>" % command) |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
406 | self.announce_ticket (bt_getissue (args[0])) |
21
8c389f46a056
- handle hg errors better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
407 | elif command == 'multierror': |
8c389f46a056
- handle hg errors better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
408 | raise logical_exception ('a\nb\nc\n') |
2
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
409 | elif command == 'idgames': |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
410 | try: |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
411 | if len(args) < 1: |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
412 | raise logical_exception ('usage: .%s <keywords>' % command) |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
413 | |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
414 | url = g_idgamesSearchURL % urllib.quote (" ".join (args[0:])) |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
415 | response = urllib2.urlopen (url).read() |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
416 | data = json.loads (response) |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
417 | |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
418 | if 'content' in data and 'file' in data['content']: |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
419 | if type (data['content']['file']) is list: |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
420 | files = data['content']['file'] |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
421 | else: |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
422 | files = [data['content']['file']] |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
423 | |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
424 | i = 0 |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
425 | for filedata in files: |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
426 | if i >= 5: |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
427 | break |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
428 | |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
429 | self.privmsg (replyto, '- %s: \'%s\' by \'%s\', rating: %s: %s' % \ |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
430 | (filedata['filename'], filedata['title'], filedata['author'], filedata['rating'], filedata['url'])) |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
431 | |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
432 | i += 1 |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
433 | self.privmsg (replyto, "(%d / %d results posted)" % (i, len(files))) |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
434 | elif 'warning' in data and 'message' in data['warning']: |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
435 | raise logical_exception (data['warning']['message']) |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
436 | elif 'error' in data and 'message' in data['error']: |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
437 | raise logical_exception (data['error']['message']) |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
438 | else: |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
439 | raise logical_exception ("Incomplete JSON response from doomworld.com/idgames") |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
440 | except logical_exception as e: |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
441 | raise e |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
442 | except Exception as e: |
1a24dd2d598e
- added a basic /idgames search
Santeri Piippo <crimsondusk64@gmail.com>
parents:
1
diff
changeset
|
443 | raise logical_exception ('Search failed: %s' % `e`) |
5
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
444 | elif command == 'restart': |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
445 | check_admin (sender, ident, host, command) |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
446 | excepterm('') |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
447 | elif command == 'update': |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
448 | check_admin (sender, ident, host, command) |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
449 | |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
450 | try: |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
451 | repo = hgapi.Repo ('.') |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
452 | r1 = repo.hg_id() |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
453 | repo.hg_pull() |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
454 | repo.hg_update('tip', True) |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
455 | r2 = repo.hg_id() |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
456 | if r1 != r2: |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
457 | self.privmsg (replyto, 'Updated to %s, restarting...' % r2) |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
458 | excepterm('') |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
459 | else: |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
460 | self.privmsg (replyto, 'Up to date at %s.' % r2) |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
461 | except hgapi.HgException as e: |
21
8c389f46a056
- handle hg errors better
Santeri Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
462 | raise logical_exception ('Update failed: %s' % str (e)) |
12
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
463 | elif command == 'addchan': |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
464 | check_admin (sender, ident, host, command) |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
465 | if len(args) != 1: |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
466 | raise logical_exception ("usage: .%s <channel>" % command) |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
467 | |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
468 | for channel in self.channels: |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
469 | if channel['name'].upper() == args[0].upper(): |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
470 | raise logical_exception ('I already know of %s!' % args[0]) |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
471 | |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
472 | chan = {} |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
473 | chan['name'] = args[0] |
19
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
474 | chan['logchannel'] = False |
12
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
475 | self.channels.append (chan) |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
476 | self.write ('JOIN ' + chan['name']) |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
477 | save_config() |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
478 | elif command == 'delchan': |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
479 | check_admin (sender, ident, host, command) |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
480 | if len(args) != 1: |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
481 | raise logical_exception ("usage: .%s <channel>" % command) |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
482 | |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
483 | for channel in self.channels: |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
484 | if channel['name'].upper() == args[0].upper(): |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
485 | break; |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
486 | else: |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
487 | raise logical_exception ('unknown channel ' + args[0]) |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
488 | |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
489 | self.channels.remove (channel) |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
490 | self.write ('PART ' + args[0]) |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
491 | save_config() |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
492 | elif command == 'chanattr': |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
493 | check_admin (sender, ident, host, command) |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
494 | |
19
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
495 | if len(args) < 1: |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
496 | raise logical_exception ("usage: .%s <attribute> [value...]" % command) |
12
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
497 | |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
498 | for channel in self.channels: |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
499 | if channel['name'] == replyto: |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
500 | break |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
501 | else: |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
502 | raise logical_exception ('I don\'t know of a channel named ' + replyto) |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
503 | |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
504 | key = args[0] |
19
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
505 | |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
506 | if len(args) < 2: |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
507 | try: |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
508 | self.privmsg (replyto, '%s = %s' % (key, channel[key])) |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
509 | except KeyError: |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
510 | self.privmsg (replyto, 'attribute %s is not set' % key) |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
511 | else: |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
512 | value = " ".join (args[1:]) |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
513 | if key == 'name': |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
514 | if replyto == channel['name']: |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
515 | replyto = value |
12
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
516 | |
19
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
517 | self.write ('PART ' + channel['name']) |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
518 | channel['name'] = value |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
519 | self.write ('JOIN ' + channel['name'] + ' ' + (channel['password'] if hasattr (channel, 'password') else '')) |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
520 | elif key == 'password': |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
521 | channel['password'] = value |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
522 | elif key == 'btannounce': |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
523 | channel['btannounce'] = bool_from_string (value) |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
524 | elif key == 'logchannel': |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
525 | channel['logchannel'] = bool_from_string (value) |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
526 | else: |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
527 | raise logical_exception ('unknown key ' + key) |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
528 | |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
529 | self.privmsg (replyto, '%s is now %s' % (key, channel[key])) |
12
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
530 | |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
531 | save_config() |
6 | 532 | elif command == 'die': |
533 | check_admin (sender, ident, host, command) | |
534 | quit() | |
19
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
535 | elif command == 'testlog': |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
536 | check_admin (sender, ident, host, command) |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
537 | if len(args) < 1: |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
538 | raise logical_exception ("usage: .%s <message...>" % command) |
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
539 | chanlog (" ".join (args)) |
5
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
540 | # else: |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
541 | # raise logical_exception ("unknown command `.%s`" % command) |
0 | 542 | |
12
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
543 | # |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
544 | # Print a ticket announce to appropriate channels |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
545 | # |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
546 | def announce_ticket (self, data): |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
547 | idstring = "%d" % data.id |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
548 | while len(idstring) < 7: |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
549 | idstring = "0" + idstring |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
550 | |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
551 | reporter = data['reporter']['name'] if hasattr (data['reporter'], 'name') else '<nobody>' |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
552 | |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
553 | for channel in self.cfg['channels']: |
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
554 | if 'btannounce' in channel and channel['btannounce'] == True: |
18
dce2b7c0b303
- when announcing new issues, include the project name
Santeri Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
555 | self.write ("PRIVMSG %s :[%s] New issue %s, reported by %s: %s: %s" % \ |
dce2b7c0b303
- when announcing new issues, include the project name
Santeri Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
556 | (channel['name'], data['project']['name'], idstring, reporter, data['summary'], self.get_ticket_url (idstring))) |
12
e843c08ee51e
- added mantisbt new ticket announcing
Santeri Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
557 | |
0 | 558 | def handle_error(self): |
559 | excepterm (traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback)) | |
560 | ||
561 | def privmsg (self, channel, msg): | |
562 | self.write ("PRIVMSG %s :%s" % (channel, msg)) | |
563 | ||
5
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
564 | def quit_irc (self): |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
565 | if self.flags & CLIF_CONNECTED: |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
566 | self.write ("QUIT :Leaving") |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
567 | self.send_all_now() |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
568 | self.close() |
b6d2b7de0a6d
- added .restart and .update
Santeri Piippo <crimsondusk64@gmail.com>
parents:
4
diff
changeset
|
569 | |
0 | 570 | def exceptdie (self): |
571 | if self.flags & CLIF_CONNECTED: | |
572 | self.write ("QUIT :Caught exception") | |
573 | self.send_all_now() | |
574 | self.close() | |
575 | ||
576 | def keyboardinterrupt (self): | |
577 | if self.flags & CLIF_CONNECTED: | |
578 | self.write ("QUIT :KeyboardInterrupt") | |
579 | self.send_all_now() | |
580 | self.close() | |
581 | ||
1
29c7e9d13a30
- fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
582 | # |
29c7e9d13a30
- fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
583 | # Main procedure: |
29c7e9d13a30
- fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
584 | # |
0 | 585 | try: |
586 | for conndata in g_config['connections']: | |
1
29c7e9d13a30
- fixed up exception handling, no longer connects to every possible connection, rather uses the autoconnect config entry
Santeri Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
587 | if conndata['name'] in g_config['autoconnect']: |
19
ca618214fd07
- control connections turned into log channels
Santeri Piippo <crimsondusk64@gmail.com>
parents:
18
diff
changeset
|
588 | irc_client (conndata, 0) |
0 | 589 | asyncore.loop() |
590 | except KeyboardInterrupt: | |
591 | for client in g_clients: | |
592 | client.keyboardinterrupt() | |
593 | quit() |