Mercurial > xib
comparison commands.py @ 180:102f895347ff
added a required "importance" argument to Bot.error()
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sat, 13 Feb 2010 16:32:28 +0100 |
parents | 891195c47350 |
children | 5af6c828c606 |
comparison
equal
deleted
inserted
replaced
179:f6c6708c6c0e | 180:102f895347ff |
---|---|
20 from argparse_modified import ArgumentParser | 20 from argparse_modified import ArgumentParser |
21 import muc | 21 import muc |
22 xmpp = muc.xmpp | 22 xmpp = muc.xmpp |
23 del muc | 23 del muc |
24 | 24 |
25 from admin import Admin | |
25 from bridge import Bridge | 26 from bridge import Bridge |
27 import say_levels | |
26 | 28 |
27 | 29 |
28 commands = ['xmpp-participants', 'irc-participants', 'xmpp-connections', 'irc-connections', 'connections', 'bridges'] | 30 commands = ['xmpp-participants', 'irc-participants', 'xmpp-connections', 'irc-connections', 'connections', 'bridges'] |
29 admin_commands = ['add-bridge', 'add-xmpp-admin', 'change-bridges-mode', 'debug', 'halt', 'remove-bridges', 'restart-bot', 'restart-bridges', 'stop-bot', 'stop-bridges'] | 31 admin_commands = ['add-bridge', 'add-xmpp-admin', 'change-bridges-mode', 'debug', 'halt', 'remove-bridges', 'restart-bot', 'restart-bridges', 'stop-bot', 'stop-bridges'] |
30 | 32 |
78 def add_bridge(bot, command, args_array, bridge): | 80 def add_bridge(bot, command, args_array, bridge): |
79 parser = ArgumentParser(prog=command) | 81 parser = ArgumentParser(prog=command) |
80 parser.add_argument('xmpp_room_jid', type=str) | 82 parser.add_argument('xmpp_room_jid', type=str) |
81 parser.add_argument('irc_chan', type=str) | 83 parser.add_argument('irc_chan', type=str) |
82 parser.add_argument('irc_server', type=str) | 84 parser.add_argument('irc_server', type=str) |
83 parser.add_argument('--mode', choices=Bridge._modes, default='normal') | 85 parser.add_argument('--mode', choices=Bridge.modes, default=Bridge.modes[0]) |
84 parser.add_argument('--say-level', choices=Bridge._say_levels, default='all') | 86 parser.add_argument('--say-level', choices=say_levels.levels, default=say_levels.levels[1]) |
85 parser.add_argument('--irc-port', type=int, default=6667) | 87 parser.add_argument('--irc-port', type=int, default=6667) |
86 try: | 88 try: |
87 args = parser.parse_args(args_array) | 89 args = parser.parse_args(args_array) |
88 except Exception as e: | 90 except Exception as e: |
89 return '\n'+e.args[1] | 91 return '\n'+e.args[1] |
94 | 96 |
95 | 97 |
96 def add_xmpp_admin(bot, command, args_array, bridge): | 98 def add_xmpp_admin(bot, command, args_array, bridge): |
97 parser = ArgumentParser(prog=command) | 99 parser = ArgumentParser(prog=command) |
98 parser.add_argument('jid', type=str) | 100 parser.add_argument('jid', type=str) |
99 try: | 101 parser.add_argument('--say-level', choices=say_levels.levels, default=say_levels.levels[1]) |
100 args = parser.parse_args(args_array) | 102 try: |
101 except Exception as e: | 103 args = parser.parse_args(args_array) |
102 return '\n'+e.args[1] | 104 except Exception as e: |
103 bot.admins_jid.append(args.jid) | 105 return '\n'+e.args[1] |
106 admin = Admin() | |
107 admin.jid = args.jid | |
108 admin.say_level = args.say_level | |
109 bot.admins.append(admin) | |
104 for b in bot.bridges: | 110 for b in bot.bridges: |
105 for p in b.participants: | 111 for p in b.participants: |
106 if p.real_jid != None and xmpp.protocol.JID(args.jid).bareMatch(p.real_jid): | 112 if p.real_jid != None and xmpp.protocol.JID(args.jid).bareMatch(p.real_jid): |
107 p.bot_admin = True | 113 p.bot_admin = True |
108 | 114 |
122 for i, b in enumerate(bot.bridges): | 128 for i, b in enumerate(bot.bridges): |
123 ret += '\n'+str(i+1)+' - '+str(b) | 129 ret += '\n'+str(i+1)+' - '+str(b) |
124 if args.show_mode: | 130 if args.show_mode: |
125 ret += ' - mode='+b.mode | 131 ret += ' - mode='+b.mode |
126 if args.show_say_level: | 132 if args.show_say_level: |
127 ret += ' - say_level='+Bridge._say_levels[b.say_level] | 133 ret += ' - say_level='+str(b.say_level) |
128 if args.show_participants: | 134 if args.show_participants: |
129 xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp']) | 135 xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp']) |
130 ret += '\nparticipants on XMPP ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) | 136 ret += '\nparticipants on XMPP ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) |
131 irc_participants_nicknames = b.get_participants_nicknames_list(protocols=['irc']) | 137 irc_participants_nicknames = b.get_participants_nicknames_list(protocols=['irc']) |
132 ret += '\nparticipants on IRC ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) | 138 ret += '\nparticipants on IRC ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames) |
136 | 142 |
137 | 143 |
138 def change_bridges_mode(bot, command, args_array, bridge): | 144 def change_bridges_mode(bot, command, args_array, bridge): |
139 parser = ArgumentParser(prog=command) | 145 parser = ArgumentParser(prog=command) |
140 parser.add_argument('bridge_id', nargs='+') | 146 parser.add_argument('bridge_id', nargs='+') |
141 parser.add_argument('new_mode', choices=Bridge._modes) | 147 parser.add_argument('new_mode', choices=Bridge.modes) |
142 try: | 148 try: |
143 args = parser.parse_args(args_array) | 149 args = parser.parse_args(args_array) |
144 except Exception as e: | 150 except Exception as e: |
145 return '\n'+e.args[1] | 151 return '\n'+e.args[1] |
146 | 152 |