From da91a1ad186a7bd7d0f330fea53ae9408be475b6 Mon Sep 17 00:00:00 2001 From: AZ Huang Date: Tue, 3 Dec 2013 03:18:52 +0800 Subject: [PATCH] More robust send group message function. --- tox-irc-sync.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tox-irc-sync.py b/tox-irc-sync.py index 5deaf86..d6fac25 100644 --- a/tox-irc-sync.py +++ b/tox-irc-sync.py @@ -79,12 +79,9 @@ class SyncBot(Tox): rx = re.match(r':(.*?)!.*? PRIVMSG %s :(.*?)\r' % CHANNEL, line, re.S) if rx: + print('IRC> %s: %s' % rx.groups()) msg = '%s> %s' % rx.groups() - print('IRC> %s' % msg) - self.sent = msg - - if self.tox_group_id != None: - self.group_message_send(self.tox_group_id, msg) + self.send_group_msg(msg) l = line.rstrip().split() if l[0] == "PING": @@ -94,6 +91,18 @@ class SyncBot(Tox): except KeyboardInterrupt: self.save_to_file('data') + def send_group_msg(self, msg): + self.sent = msg + if self.tox_group_id != None: + sent = False + while not sent: + try: + self.group_message_send(self.tox_group_id, msg) + sent = True + except: + self.do() + sleep(0.02) + def on_group_invite(self, friendid, pk): if not self.joined: self.joined = True