From 6b26cc188e69c0b89876abec2788be3a2d20c09f Mon Sep 17 00:00:00 2001 From: AZ Huang Date: Thu, 20 Feb 2014 19:02:07 +0800 Subject: [PATCH] Some refactor. --- tox-irc-sync.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tox-irc-sync.py b/tox-irc-sync.py index b1664ef..3a4c270 100644 --- a/tox-irc-sync.py +++ b/tox-irc-sync.py @@ -95,12 +95,8 @@ class SyncBot(Tox): msg = '[%s]: %s' % rx.groups() content = rx.group(2) - if content == '^syncbot' or \ - content == '^echobot': - self.irc_send('PRIVMSG %s :%s\r\n' % - (CHANNEL, self.get_address())) - self.ensure_exe(self.group_message_send, - (self.tox_group_id, self.get_address())) + if content.startswith('^'): + self.handle_command(content) elif content[1:].startswith('ACTION '): action = '[%s]: %s' % (rx.group(1), rx.group(2)[8:-1]) @@ -152,6 +148,7 @@ class SyncBot(Tox): print('TOX> %s: %s' % (name, message)) if message.startswith('^'): self.irc_send('PRIVMSG %s :%s\r\n' % (CHANNEL, message)) + self.handle_command(cmd) else: self.irc_send('PRIVMSG %s :[%s]: %s\r\n' % (CHANNEL, name, message)) @@ -175,5 +172,12 @@ class SyncBot(Tox): else: self.ensure_exe(self.send_message, (friendid, message)) + def handle_command(self, cmd): + if cmd[1:] in ['syncbot', 'echobot']: + self.ensure_exe(self.group_message_send, + (self.tox_group_id, self.get_address())) + self.irc_send('PRIVMSG %s :%s\r\n' % + (CHANNEL, self.get_address())) + t = SyncBot() t.loop()