More robust send group message function.

This commit is contained in:
AZ Huang 2013-12-03 03:18:52 +08:00
parent 33518e0b2d
commit da91a1ad18
1 changed files with 14 additions and 5 deletions

View File

@ -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