Sat, 30 Aug 2014 20:22:16 +0300
- made cobalt die if autoconnect entries cannot be found plus other stuff
cobalt.py | file | annotate | diff | comparison | revisions |
--- a/cobalt.py Sat Jul 12 23:05:31 2014 +0300 +++ b/cobalt.py Sat Aug 30 20:22:16 2014 +0300 @@ -61,6 +61,7 @@ g_mynick = g_config['nickname'] g_idgamesSearchURL = 'http://www.doomworld.com/idgames/api/api.php?action=search&query=%s&type=title&sort=date&out=json' +g_BotActive = False # # SOAP stuff @@ -183,8 +184,10 @@ else: client.quit_irc() - restart_self() - #quit() + if g_BotActive: + restart_self() + else: + quit() sys.excepthook = handle_exception @@ -224,6 +227,8 @@ for channel in self.channels: if not 'logchannel' in channel: channel['logchannel'] = False + channel['namesdone'] = True + channel['haslinkbot'] = False if not 'conflictsuffix' in self.cfg: self.cfg['conflictsuffix'] = '`' @@ -299,6 +304,12 @@ self.write ('MODE %s %s' % (self.mynick, self.cfg['umode'])) elif words[1] == "PRIVMSG": self.handle_privmsg (line) + elif words[1] == 'JOIN': + rex = re.compile (r'^:([^!]+)!([^@]+)@([^ ]+) JOIN :#(.+)') + match = rex.match (line) + + if match and match.group(1).toLower() == 'linkbot': + channel_by_name (match.group(4))['haslinkbot'] = True elif words[1] == 'QUIT': rex = re.compile (r'^:([^!]+)!([^@]+)@([^ ]+) QUIT') match = rex.match (line) @@ -307,6 +318,10 @@ if match and match.group(1) == self.desired_name: self.mynick = self.desired_name self.write ("NICK %s" % self.mynick) + + if match and match.group(1).toLower() == 'linkbot': + for channel in self.channels: + channels['haslinkbot'] = False elif words[1] == "433": #:irc.localhost 433 * cobalt :Nickname is already in use. self.mynick = '%s%s' % (self.mynick, self.cfg['conflictsuffix']) @@ -315,6 +330,13 @@ # Check for new issues on the bugtracker bt_checklatest() + def channel_by_name (self, name): + for channel in self.channels: + if channel['name'].upper() == args[0].upper(): + return channel + else: + raise logical_exception ('unknown channel ' + args[0]) + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Handle a PRIVMSG line from the IRC server @@ -585,31 +607,34 @@ def privmsg (self, channel, msg): self.write ("PRIVMSG %s :%s" % (channel, msg)) - def quit_irc (self): + def close_connection (self, message): if self.flags & CLIF_CONNECTED: - self.write ("QUIT :Leaving") + self.write ("QUIT :" + message) self.send_all_now() self.close() + def quit_irc (self): + self.close_connection ('Leaving') + def exceptdie (self): - if self.flags & CLIF_CONNECTED: - self.write ("QUIT :Caught exception") - self.send_all_now() - self.close() + self.close_connection ('Caught exception') def keyboardinterrupt (self): - if self.flags & CLIF_CONNECTED: - self.write ("QUIT :KeyboardInterrupt") - self.send_all_now() - self.close() + self.close_connection ('KeyboardInterrupt') # # Main procedure: # try: - for conndata in g_config['connections']: - if conndata['name'] in g_config['autoconnect']: - irc_client (conndata, 0) + for aconn in g_config['autoconnect']: + for conndata in g_config['connections']: + if conndata['name'] == aconn: + irc_client (conndata, 0) + break + else: + raise logical_exception ("unknown autoconnect entry %s" % (aconn)) + + g_BotActive = True asyncore.loop() except KeyboardInterrupt: for client in g_clients: