From c2e68b9e4058526b62ce9fa5f6809a02514cc345 Mon Sep 17 00:00:00 2001 From: AZ Huang Date: Thu, 12 Dec 2013 00:02:01 +0800 Subject: [PATCH] Fix exception. --- tox-irc-sync.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tox-irc-sync.py b/tox-irc-sync.py index ebb578f..ed5273e 100644 --- a/tox-irc-sync.py +++ b/tox-irc-sync.py @@ -44,13 +44,12 @@ class SyncBot(Tox): def ensure_exe(self, func, args): count = 0 - THRESHOLD = 10 + THRESHOLD = 50 while True: try: return func(*args) except: - print func, count assert count < THRESHOLD count += 1 for i in range(10): @@ -60,6 +59,7 @@ class SyncBot(Tox): def loop(self): checked = False self.joined = False + self.request = False try: while True: @@ -67,8 +67,11 @@ class SyncBot(Tox): if not checked and status: print('Connected to DHT.') checked = True - self.ensure_exe(self.add_friend, (GROUP_BOT, "")) - self.bid = self.get_friend_id(GROUP_BOT) + try: + self.bid = self.get_friend_id(GROUP_BOT) + except: + self.ensure_exe(self.add_friend, (GROUP_BOT, "Hi")) + self.bid = self.get_friend_id(GROUP_BOT) if checked and not status: print('Disconnected from DHT.') @@ -105,9 +108,11 @@ class SyncBot(Tox): self.save_to_file('data') def on_connection_status(self, friendId, status): - if not self.joined and friendId == self.bid and status: + if not self.request and not self.joined \ + and friendId == self.bid and status: print('Groupbot online, trying to join group chat.') - self.ensure_exe(self.send_message, (tid, 'invite')) + self.request = True + self.ensure_exe(self.send_message, (self.bid, 'invite')) def on_group_invite(self, friendid, pk): if not self.joined: