Mercurial > xib
comparison bot.py @ 113:6daf0854aa9f
added "--show-say-level" and "--show-participants" options to the "bridges" command, renamed {irc,xmpp}_participants commands
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Fri, 27 Nov 2009 23:45:47 +0100 |
parents | a817ad05dd1d |
children | 0ae0f8836a7a |
comparison
equal
deleted
inserted
replaced
112:a817ad05dd1d | 113:6daf0854aa9f |
---|---|
37 import shlex | 37 import shlex |
38 | 38 |
39 | 39 |
40 class bot(Thread): | 40 class bot(Thread): |
41 | 41 |
42 commands = ['xmpp_participants', 'irc_participants', 'bridges'] | 42 commands = ['xmpp-participants', 'irc-participants', 'bridges'] |
43 admin_commands = ['add-bridge', 'add-xmpp-admin', 'halt', 'remove-bridge', 'restart-bot', 'restart-bridge', 'stop-bridge'] | 43 admin_commands = ['add-bridge', 'add-xmpp-admin', 'halt', 'remove-bridge', 'restart-bot', 'restart-bridge', 'stop-bridge'] |
44 | 44 |
45 def __init__(self, jid, password, nickname, admins_jid=[], error_fd=sys.stderr, debug=False): | 45 def __init__(self, jid, password, nickname, admins_jid=[], error_fd=sys.stderr, debug=False): |
46 Thread.__init__(self) | 46 Thread.__init__(self) |
47 self.bare_jid = xmpp.protocol.JID(jid=jid) | 47 self.bare_jid = xmpp.protocol.JID(jid=jid) |
845 command = command[0] | 845 command = command[0] |
846 | 846 |
847 if isinstance(participant_, participant) and bot_admin != participant_.bot_admin: | 847 if isinstance(participant_, participant) and bot_admin != participant_.bot_admin: |
848 bot_admin = participant_.bot_admin | 848 bot_admin = participant_.bot_admin |
849 | 849 |
850 if command == 'xmpp_participants': | 850 if command == 'xmpp-participants': |
851 if not isinstance(participant_, participant): | 851 if not isinstance(participant_, participant): |
852 for b in self.bridges: | 852 for b in self.bridges: |
853 xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp']) | 853 xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp']) |
854 ret += '\nparticipants on '+b.xmpp_room_jid+' ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) | 854 ret += '\nparticipants on '+b.xmpp_room_jid+' ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) |
855 return ret | 855 return ret |
856 else: | 856 else: |
857 xmpp_participants_nicknames = participant_.bridge.get_participants_nicknames_list(protocols=['xmpp']) | 857 xmpp_participants_nicknames = participant_.bridge.get_participants_nicknames_list(protocols=['xmpp']) |
858 return 'participants on '+participant_.bridge.xmpp_room_jid+' ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) | 858 return '\nparticipants on '+participant_.bridge.xmpp_room_jid+' ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) |
859 | 859 |
860 elif command == 'irc_participants': | 860 elif command == 'irc-participants': |
861 if not isinstance(participant_, participant): | 861 if not isinstance(participant_, participant): |
862 for b in self.bridges: | 862 for b in self.bridges: |
863 irc_participants_nicknames = b.get_participants_nicknames_list(protocols=['irc']) | 863 irc_participants_nicknames = b.get_participants_nicknames_list(protocols=['irc']) |
864 ret += '\nparticipants on '+b.irc_room+' at '+b.irc_server+' ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) | 864 ret += '\nparticipants on '+b.irc_room+' at '+b.irc_server+' ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) |
865 return ret | 865 return ret |
866 else: | 866 else: |
867 irc_participants_nicknames = participant_.bridge.get_participants_nicknames_list(protocols=['irc']) | 867 irc_participants_nicknames = participant_.bridge.get_participants_nicknames_list(protocols=['irc']) |
868 return 'participants on '+participant_.bridge.irc_room+' at '+participant_.bridge.irc_server+' ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) | 868 return '\nparticipants on '+participant_.bridge.irc_room+' at '+participant_.bridge.irc_server+' ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) |
869 | 869 |
870 elif command == 'bridges': | 870 elif command == 'bridges': |
871 parser = ArgumentParser(prog=command) | 871 parser = ArgumentParser(prog=command) |
872 parser.add_argument('--show-mode', default=False, action='store_true') | 872 parser.add_argument('--show-mode', default=False, action='store_true') |
873 parser.add_argument('--show-say-level', default=False, action='store_true') | |
874 parser.add_argument('--show-participants', default=False, action='store_true') | |
873 try: | 875 try: |
874 args = parser.parse_args(args_array) | 876 args = parser.parse_args(args_array) |
875 except ParseException as e: | 877 except ParseException as e: |
876 return '\n'+e.args[1] | 878 return '\n'+e.args[1] |
877 ret = 'List of bridges:' | 879 ret = 'List of bridges:' |
878 for i, b in enumerate(self.bridges): | 880 for i, b in enumerate(self.bridges): |
879 ret += '\n'+str(i+1)+' - '+str(b) | 881 ret += '\n'+str(i+1)+' - '+str(b) |
880 if args.show_mode: | 882 if args.show_mode: |
881 ret += ' - '+b.mode+' mode' | 883 ret += ' - mode='+b.mode |
884 if args.show_say_level: | |
885 ret += ' - say_level='+bridge._say_levels[b.say_level] | |
886 if args.show_participants: | |
887 xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp']) | |
888 ret += '\nparticipants on XMPP ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) | |
889 irc_participants_nicknames = b.get_participants_nicknames_list(protocols=['irc']) | |
890 ret += '\nparticipants on IRC ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) | |
882 if b.irc_connection == None: | 891 if b.irc_connection == None: |
883 ret += ' - this bridge is stopped, use "restart-bridge '+str(i+1)+'" to restart it' | 892 ret += ' - this bridge is stopped, use "restart-bridge '+str(i+1)+'" to restart it' |
884 return ret | 893 return ret |
885 | 894 |
886 elif command in bot.admin_commands: | 895 elif command in bot.admin_commands: |