80 |
80 |
81 def bt_updatechecktimeout(): |
81 def bt_updatechecktimeout(): |
82 global btannounce_timeout |
82 global btannounce_timeout |
83 btannounce_timeout = time.time() + (cfg ('btlatest_checkinterval', 5) * 60) |
83 btannounce_timeout = time.time() + (cfg ('btlatest_checkinterval', 5) * 60) |
84 |
84 |
|
85 def bool_from_string (value): |
|
86 if value != 'true' and value != 'false': |
|
87 raise logical_exception ('expected true or false for value') |
|
88 return True if value == 'true' else False |
|
89 |
85 if suds_active: |
90 if suds_active: |
86 try: |
91 try: |
87 btannounce_id = suds_client.service.mc_issue_get_biggest_id (g_config['trackeruser'], g_config ['trackerpassword'], 0) |
92 btannounce_id = suds_client.service.mc_issue_get_biggest_id (g_config['trackeruser'], g_config ['trackerpassword'], 0) |
88 btannounce_active = True |
93 btannounce_active = True |
89 bt_updatechecktimeout() |
94 bt_updatechecktimeout() |
135 |
139 |
136 def __init__ (self, name): |
140 def __init__ (self, name): |
137 self.name = name |
141 self.name = name |
138 |
142 |
139 # |
143 # |
140 # Prints a line to control channel(s) |
144 # Prints a line to log channel(s) |
141 # |
145 # |
142 def control (line): |
146 def chanlog (line): |
143 for client in g_clients: |
147 for client in g_clients: |
144 if client.flags & (CLIF_CONTROL|CLIF_CONNECTED) == (CLIF_CONTROL|CLIF_CONNECTED): |
148 if not client.flags & CLIF_CONNECTED: |
145 client.write ("PRIVMSG %s :%s" % (client.channels[0]['name'], line)) |
149 continue |
|
150 |
|
151 for channel in client.channels: |
|
152 if channel['logchannel']: |
|
153 client.write ("PRIVMSG %s :%s" % (channel['name'], line)) |
146 |
154 |
147 # |
155 # |
148 # Exception handling |
156 # Exception handling |
149 # |
157 # |
150 def handle_exception(excType, excValue, trace): |
158 def handle_exception(excType, excValue, trace): |
196 self.cfg = cfg |
206 self.cfg = cfg |
197 self.mynick = '' |
207 self.mynick = '' |
198 self.verbose = g_config['verbose'] if 'verbose' in g_config else False |
208 self.verbose = g_config['verbose'] if 'verbose' in g_config else False |
199 self.commandprefix = g_config['commandprefix'][0] if 'commandprefix' in g_config else '.' |
209 self.commandprefix = g_config['commandprefix'][0] if 'commandprefix' in g_config else '.' |
200 |
210 |
|
211 for channel in self.channels: |
|
212 if not 'logchannel' in channel: |
|
213 channel['logchannel'] = False |
|
214 |
201 if not 'conflictsuffix' in self.cfg: |
215 if not 'conflictsuffix' in self.cfg: |
202 self.cfg['conflictsuffix'] = '`' |
216 self.cfg['conflictsuffix'] = '`' |
203 |
217 |
204 self.desired_name = self.cfg['nickname'] if 'nickname' in self.cfg else g_config['nickname'] |
218 self.desired_name = self.cfg['nickname'] if 'nickname' in self.cfg else g_config['nickname'] |
205 g_clients.append (self) |
219 g_clients.append (self) |
317 except logical_exception as msg: |
331 except logical_exception as msg: |
318 self.privmsg (replyto, "error: %s" % msg) |
332 self.privmsg (replyto, "error: %s" % msg) |
319 elif http_match: |
333 elif http_match: |
320 self.get_ticket_data (replyto, http_match.group (2), False) |
334 self.get_ticket_data (replyto, http_match.group (2), False) |
321 else: |
335 else: |
322 control ("Recieved bad PRIVMSG: %s" % line) |
336 chanlog ("Recieved bad PRIVMSG: %s" % line) |
323 |
337 |
324 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
338 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
325 # |
339 # |
326 # Get the URL for a specified ticket |
340 # Get the URL for a specified ticket |
327 # |
341 # |
439 if channel['name'].upper() == args[0].upper(): |
453 if channel['name'].upper() == args[0].upper(): |
440 raise logical_exception ('I already know of %s!' % args[0]) |
454 raise logical_exception ('I already know of %s!' % args[0]) |
441 |
455 |
442 chan = {} |
456 chan = {} |
443 chan['name'] = args[0] |
457 chan['name'] = args[0] |
|
458 chan['logchannel'] = False |
444 self.channels.append (chan) |
459 self.channels.append (chan) |
445 self.write ('JOIN ' + chan['name']) |
460 self.write ('JOIN ' + chan['name']) |
446 save_config() |
461 save_config() |
447 elif command == 'delchan': |
462 elif command == 'delchan': |
448 check_admin (sender, ident, host, command) |
463 check_admin (sender, ident, host, command) |
459 self.write ('PART ' + args[0]) |
474 self.write ('PART ' + args[0]) |
460 save_config() |
475 save_config() |
461 elif command == 'chanattr': |
476 elif command == 'chanattr': |
462 check_admin (sender, ident, host, command) |
477 check_admin (sender, ident, host, command) |
463 |
478 |
464 if len(args) < 2: |
479 if len(args) < 1: |
465 raise logical_exception ("usage: .%s <attribute> <value...>" % command) |
480 raise logical_exception ("usage: .%s <attribute> [value...]" % command) |
466 |
481 |
467 for channel in self.channels: |
482 for channel in self.channels: |
468 if channel['name'] == replyto: |
483 if channel['name'] == replyto: |
469 break |
484 break |
470 else: |
485 else: |
471 raise logical_exception ('I don\'t know of a channel named ' + replyto) |
486 raise logical_exception ('I don\'t know of a channel named ' + replyto) |
472 |
487 |
473 key = args[0] |
488 key = args[0] |
474 value = ' '.join (args[1:]) |
489 |
475 |
490 if len(args) < 2: |
476 if key == 'name': |
491 try: |
477 self.write ('PART ' + channel['name']) |
492 self.privmsg (replyto, '%s = %s' % (key, channel[key])) |
478 channel['name'] = value |
493 except KeyError: |
479 self.write ('JOIN ' + channel['name'] + ' ' + (channel['password'] if hasattr (channel, 'password') else '')) |
494 self.privmsg (replyto, 'attribute %s is not set' % key) |
480 elif key == 'password': |
|
481 channel['password'] = value |
|
482 elif key == 'btannounce': |
|
483 if value != 'true' and value != 'false': |
|
484 raise logical_exception ('expected true or false for value') |
|
485 channel['btannounce'] = True if value == 'true' else False |
|
486 else: |
495 else: |
487 raise logical_exception ('unknown key ' + key) |
496 value = " ".join (args[1:]) |
|
497 if key == 'name': |
|
498 if replyto == channel['name']: |
|
499 replyto = value |
|
500 |
|
501 self.write ('PART ' + channel['name']) |
|
502 channel['name'] = value |
|
503 self.write ('JOIN ' + channel['name'] + ' ' + (channel['password'] if hasattr (channel, 'password') else '')) |
|
504 elif key == 'password': |
|
505 channel['password'] = value |
|
506 elif key == 'btannounce': |
|
507 channel['btannounce'] = bool_from_string (value) |
|
508 elif key == 'logchannel': |
|
509 channel['logchannel'] = bool_from_string (value) |
|
510 else: |
|
511 raise logical_exception ('unknown key ' + key) |
|
512 |
|
513 self.privmsg (replyto, '%s is now %s' % (key, channel[key])) |
488 |
514 |
489 save_config() |
515 save_config() |
490 elif command == 'die': |
516 elif command == 'die': |
491 check_admin (sender, ident, host, command) |
517 check_admin (sender, ident, host, command) |
492 quit() |
518 quit() |
|
519 elif command == 'testlog': |
|
520 check_admin (sender, ident, host, command) |
|
521 if len(args) < 1: |
|
522 raise logical_exception ("usage: .%s <message...>" % command) |
|
523 chanlog (" ".join (args)) |
493 # else: |
524 # else: |
494 # raise logical_exception ("unknown command `.%s`" % command) |
525 # raise logical_exception ("unknown command `.%s`" % command) |
495 |
526 |
496 # |
527 # |
497 # Print a ticket announce to appropriate channels |
528 # Print a ticket announce to appropriate channels |
536 # Main procedure: |
567 # Main procedure: |
537 # |
568 # |
538 try: |
569 try: |
539 for conndata in g_config['connections']: |
570 for conndata in g_config['connections']: |
540 if conndata['name'] in g_config['autoconnect']: |
571 if conndata['name'] in g_config['autoconnect']: |
541 irc_client (conndata, CLIF_CONTROL if conndata['control'] else 0) |
572 irc_client (conndata, 0) |
542 asyncore.loop() |
573 asyncore.loop() |
543 except KeyboardInterrupt: |
574 except KeyboardInterrupt: |
544 for client in g_clients: |
575 for client in g_clients: |
545 client.keyboardinterrupt() |
576 client.keyboardinterrupt() |
546 quit() |
577 quit() |