annotate commands.py @ 254:3b930e2fad43

minor fix in Participant Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Thu, 11 Mar 2010 14:01:20 +0100
parents 70938f01be8f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1 #!/usr/bin/env python
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
3
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
4 # This program is free software: you can redistribute it and/or modify
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
5 # it under the terms of the GNU General Public License as published by
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
6 # the Free Software Foundation, either version 3 of the License, or
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
7 # (at your option) any later version.
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
8 #
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
9 # This program is distributed in the hope that it will be useful,
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
12 # GNU General Public License for more details.
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
13 #
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
14 # You should have received a copy of the GNU General Public License
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
16
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
17
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
18 import shlex
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
19
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
20 from argparse_modified import ArgumentParser
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
21 import muc
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
22 xmpp = muc.xmpp
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
23 del muc
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
24
180
102f895347ff added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents: 178
diff changeset
25 from admin import Admin
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
26 from bridge import Bridge
180
102f895347ff added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents: 178
diff changeset
27 import say_levels
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
28
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
29
143
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
30 commands = ['xmpp-participants', 'irc-participants', 'xmpp-connections', 'irc-connections', 'connections', 'bridges']
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
31 admin_commands = ['add-bridge', 'add-xmpp-admin', 'change-bridges-mode', 'debug', 'halt', 'remove-bridges', 'restart-bot', 'restart-bridges', 'stop-bot', 'stop-bridges']
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
32
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
33 def execute(bot, command_line, bot_admin, bridge):
227
87fa6bc893de (commands) convert unicode to string before passing it to shlex
Charly COSTE <changaco@changaco.net>
parents: 216
diff changeset
34 command = shlex.split(str(command_line))
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
35 if len(command) > 1:
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
36 args_array = command[1:]
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
37 else:
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
38 args_array = []
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
39 command = command[0]
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
40 command_func = command.replace('-', '_')
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
41
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
42 if not globals().has_key(command_func):
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
43 ret = 'Error: "'+command+'" is not a valid command.\ncommands: '+' '.join(commands)
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
44 if bot_admin:
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
45 return ret+'\n'+'admin commands: '+' '.join(admin_commands)
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
46 else:
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
47 return ret
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
48 elif command in admin_commands and not bot_admin:
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
49 return 'You have to be a bot admin to use this command.'
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
50
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
51 return globals()[command_func](bot, command, args_array, bridge)
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
52
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
53
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
54 def _find_bridges(bot, args_array):
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
55 ret = ''
216
d527d7b75f56 merged Bot.find_bridges and Bot.get_bridges into Bot.iter_bridges, btw we don't need to lock Bot.bridges because lists don't raise RuntimeError
Charly COSTE <changaco@changaco.net>
parents: 203
diff changeset
56 matches = []
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
57 for arg in args_array:
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
58 try:
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
59 bn = int(arg)
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
60 if bn < 1:
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
61 raise IndexError
216
d527d7b75f56 merged Bot.find_bridges and Bot.get_bridges into Bot.iter_bridges, btw we don't need to lock Bot.bridges because lists don't raise RuntimeError
Charly COSTE <changaco@changaco.net>
parents: 203
diff changeset
62 matches.append(bot.bridges[bn-1])
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
63 except IndexError:
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
64 ret += '\nInvalid bridge number "'+str(bn)+'".'
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
65 except ValueError:
216
d527d7b75f56 merged Bot.find_bridges and Bot.get_bridges into Bot.iter_bridges, btw we don't need to lock Bot.bridges because lists don't raise RuntimeError
Charly COSTE <changaco@changaco.net>
parents: 203
diff changeset
66 found_bridges = [b for b in bot.iter_bridges(patterns=[arg])]
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
67 if len(found_bridges) == 0:
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
68 ret += '\nNo bridge found matching "'+arg+'".'
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
69 else:
216
d527d7b75f56 merged Bot.find_bridges and Bot.get_bridges into Bot.iter_bridges, btw we don't need to lock Bot.bridges because lists don't raise RuntimeError
Charly COSTE <changaco@changaco.net>
parents: 203
diff changeset
70 matches.extend(found_bridges)
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
71
216
d527d7b75f56 merged Bot.find_bridges and Bot.get_bridges into Bot.iter_bridges, btw we don't need to lock Bot.bridges because lists don't raise RuntimeError
Charly COSTE <changaco@changaco.net>
parents: 203
diff changeset
72 if ret != '' or len(matches) == 0:
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
73 if ret != '':
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
74 ret += '\n\n'
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
75 ret += bridges(bot, 'bridges', [], None)+'\n\n'
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
76
216
d527d7b75f56 merged Bot.find_bridges and Bot.get_bridges into Bot.iter_bridges, btw we don't need to lock Bot.bridges because lists don't raise RuntimeError
Charly COSTE <changaco@changaco.net>
parents: 203
diff changeset
77 return (matches, ret)
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
78
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
79
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
80 def add_bridge(bot, command, args_array, bridge):
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
81 parser = ArgumentParser(prog=command)
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
82 parser.add_argument('xmpp_room_jid', type=str)
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
83 parser.add_argument('irc_chan', type=str)
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
84 parser.add_argument('irc_server', type=str)
180
102f895347ff added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents: 178
diff changeset
85 parser.add_argument('--mode', choices=Bridge.modes, default=Bridge.modes[0])
102f895347ff added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents: 178
diff changeset
86 parser.add_argument('--say-level', choices=say_levels.levels, default=say_levels.levels[1])
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
87 parser.add_argument('--irc-port', type=int, default=6667)
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
88 try:
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
89 args = parser.parse_args(args_array)
178
891195c47350 catch all exceptions in commands.py
Charly COSTE <changaco@changaco.net>
parents: 173
diff changeset
90 except Exception as e:
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
91 return '\n'+e.args[1]
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
92
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
93 bot.new_bridge(args.xmpp_room_jid, args.irc_chan, args.irc_server, args.mode, args.say_level, irc_port=args.irc_port)
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
94
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
95 return 'Bridge added.'
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
96
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
97
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
98 def add_xmpp_admin(bot, command, args_array, bridge):
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
99 parser = ArgumentParser(prog=command)
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
100 parser.add_argument('jid', type=str)
180
102f895347ff added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents: 178
diff changeset
101 parser.add_argument('--say-level', choices=say_levels.levels, default=say_levels.levels[1])
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
102 try:
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
103 args = parser.parse_args(args_array)
178
891195c47350 catch all exceptions in commands.py
Charly COSTE <changaco@changaco.net>
parents: 173
diff changeset
104 except Exception as e:
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
105 return '\n'+e.args[1]
180
102f895347ff added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents: 178
diff changeset
106 admin = Admin()
102f895347ff added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents: 178
diff changeset
107 admin.jid = args.jid
102f895347ff added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents: 178
diff changeset
108 admin.say_level = args.say_level
102f895347ff added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents: 178
diff changeset
109 bot.admins.append(admin)
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
110 for b in bot.bridges:
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
111 for p in b.participants:
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
112 if p.real_jid != None and xmpp.protocol.JID(args.jid).bareMatch(p.real_jid):
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
113 p.bot_admin = True
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
114
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
115 return 'XMPP admin added.'
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
116
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
117
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
118 def bridges(bot, command, args_array, bridge):
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
119 parser = ArgumentParser(prog=command)
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
120 parser.add_argument('--show-mode', default=False, action='store_true')
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
121 parser.add_argument('--show-say-level', default=False, action='store_true')
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
122 parser.add_argument('--show-participants', default=False, action='store_true')
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
123 try:
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
124 args = parser.parse_args(args_array)
178
891195c47350 catch all exceptions in commands.py
Charly COSTE <changaco@changaco.net>
parents: 173
diff changeset
125 except Exception as e:
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
126 return '\n'+e.args[1]
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
127 ret = 'List of bridges:'
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
128 for i, b in enumerate(bot.bridges):
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
129 ret += '\n'+str(i+1)+' - '+str(b)
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
130 if args.show_mode:
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
131 ret += ' - mode='+b.mode
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
132 if args.show_say_level:
180
102f895347ff added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents: 178
diff changeset
133 ret += ' - say_level='+str(b.say_level)
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
134 if args.show_participants:
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
135 xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp'])
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
136 ret += '\nparticipants on XMPP ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames)
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
137 irc_participants_nicknames = b.get_participants_nicknames_list(protocols=['irc'])
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
138 ret += '\nparticipants on IRC ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames)
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
139 if b.irc_connection == None:
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
140 ret += ' - this bridge is stopped, use "restart-bridges '+str(i+1)+'" to restart it'
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
141 return ret
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
142
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
143
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
144 def change_bridges_mode(bot, command, args_array, bridge):
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
145 parser = ArgumentParser(prog=command)
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
146 parser.add_argument('bridge_id', nargs='+')
180
102f895347ff added a required "importance" argument to Bot.error()
Charly COSTE <changaco@changaco.net>
parents: 178
diff changeset
147 parser.add_argument('new_mode', choices=Bridge.modes)
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
148 try:
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
149 args = parser.parse_args(args_array)
178
891195c47350 catch all exceptions in commands.py
Charly COSTE <changaco@changaco.net>
parents: 173
diff changeset
150 except Exception as e:
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
151 return '\n'+e.args[1]
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
152
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
153 found_bridges, ret = _find_bridges(bot, args.bridge_id)
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
154 for found_bridge in found_bridges:
203
2a81c480439a renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents: 194
diff changeset
155 r = found_bridge.change_mode(args.new_mode)
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
156 if r:
168
d3b619cd60fb minor fix of the output of the change-bridges-mode command
Charly COSTE <changaco@changaco.net>
parents: 160
diff changeset
157 ret += r+'\n'
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
158
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
159 if ret:
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
160 return ret
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
161 return 'Modes changed.'
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
162
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
163
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
164 def connections(bot, command, args_array, bridge):
143
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
165 parser = ArgumentParser(prog=command)
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
166 parser.add_argument('--verbose', '-v', default=False, action='store_true')
173
6c4aaf8f3733 added "--sort" option to the "connections" command
Charly COSTE <changaco@changaco.net>
parents: 168
diff changeset
167 parser.add_argument('--sort', '-s', default=False, action='store_true')
143
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
168 try:
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
169 args = parser.parse_args(args_array)
178
891195c47350 catch all exceptions in commands.py
Charly COSTE <changaco@changaco.net>
parents: 173
diff changeset
170 except Exception as e:
143
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
171 return '\n'+e.args[1]
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
172 return irc_connections(bot, 'irc-connections', args_array, bridge)+'\n'+xmpp_connections(bot, 'xmpp-connections', args_array, bridge)
143
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
173
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
174
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
175 def debug(bot, command, args_array, bridge):
153
0a8f96a1d200 added a "debug" command to be able to change the value of Bot.debug without restarting the bot
Charly COSTE <changaco@changaco.net>
parents: 143
diff changeset
176 parser = ArgumentParser(prog=command)
0a8f96a1d200 added a "debug" command to be able to change the value of Bot.debug without restarting the bot
Charly COSTE <changaco@changaco.net>
parents: 143
diff changeset
177 parser.add_argument('mode', choices=['on', 'off'])
0a8f96a1d200 added a "debug" command to be able to change the value of Bot.debug without restarting the bot
Charly COSTE <changaco@changaco.net>
parents: 143
diff changeset
178 try:
0a8f96a1d200 added a "debug" command to be able to change the value of Bot.debug without restarting the bot
Charly COSTE <changaco@changaco.net>
parents: 143
diff changeset
179 args = parser.parse_args(args_array)
178
891195c47350 catch all exceptions in commands.py
Charly COSTE <changaco@changaco.net>
parents: 173
diff changeset
180 except Exception as e:
153
0a8f96a1d200 added a "debug" command to be able to change the value of Bot.debug without restarting the bot
Charly COSTE <changaco@changaco.net>
parents: 143
diff changeset
181 if len(args_array) == 0:
0a8f96a1d200 added a "debug" command to be able to change the value of Bot.debug without restarting the bot
Charly COSTE <changaco@changaco.net>
parents: 143
diff changeset
182 if bot.debug:
0a8f96a1d200 added a "debug" command to be able to change the value of Bot.debug without restarting the bot
Charly COSTE <changaco@changaco.net>
parents: 143
diff changeset
183 return 'Debugging is on'
0a8f96a1d200 added a "debug" command to be able to change the value of Bot.debug without restarting the bot
Charly COSTE <changaco@changaco.net>
parents: 143
diff changeset
184 else:
0a8f96a1d200 added a "debug" command to be able to change the value of Bot.debug without restarting the bot
Charly COSTE <changaco@changaco.net>
parents: 143
diff changeset
185 return 'Debugging is off'
0a8f96a1d200 added a "debug" command to be able to change the value of Bot.debug without restarting the bot
Charly COSTE <changaco@changaco.net>
parents: 143
diff changeset
186 else:
0a8f96a1d200 added a "debug" command to be able to change the value of Bot.debug without restarting the bot
Charly COSTE <changaco@changaco.net>
parents: 143
diff changeset
187 return '\n'+e.args[1]
0a8f96a1d200 added a "debug" command to be able to change the value of Bot.debug without restarting the bot
Charly COSTE <changaco@changaco.net>
parents: 143
diff changeset
188
0a8f96a1d200 added a "debug" command to be able to change the value of Bot.debug without restarting the bot
Charly COSTE <changaco@changaco.net>
parents: 143
diff changeset
189 if args.mode == 'on':
0a8f96a1d200 added a "debug" command to be able to change the value of Bot.debug without restarting the bot
Charly COSTE <changaco@changaco.net>
parents: 143
diff changeset
190 bot.debug = True
0a8f96a1d200 added a "debug" command to be able to change the value of Bot.debug without restarting the bot
Charly COSTE <changaco@changaco.net>
parents: 143
diff changeset
191 return 'Debugging is now on'
0a8f96a1d200 added a "debug" command to be able to change the value of Bot.debug without restarting the bot
Charly COSTE <changaco@changaco.net>
parents: 143
diff changeset
192 else:
0a8f96a1d200 added a "debug" command to be able to change the value of Bot.debug without restarting the bot
Charly COSTE <changaco@changaco.net>
parents: 143
diff changeset
193 bot.debug = False
0a8f96a1d200 added a "debug" command to be able to change the value of Bot.debug without restarting the bot
Charly COSTE <changaco@changaco.net>
parents: 143
diff changeset
194 return 'Debugging is now off'
0a8f96a1d200 added a "debug" command to be able to change the value of Bot.debug without restarting the bot
Charly COSTE <changaco@changaco.net>
parents: 143
diff changeset
195
0a8f96a1d200 added a "debug" command to be able to change the value of Bot.debug without restarting the bot
Charly COSTE <changaco@changaco.net>
parents: 143
diff changeset
196
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
197 def halt(bot, command, args_array, bridge):
155
63db565438bd fixed the halt command
Charly COSTE <changaco@changaco.net>
parents: 153
diff changeset
198 bot.__del__()
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
199 return
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
200
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
201
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
202 def irc_connections(bot, command, args_array, bridge):
143
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
203 parser = ArgumentParser(prog=command)
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
204 parser.add_argument('--verbose', '-v', default=False, action='store_true')
173
6c4aaf8f3733 added "--sort" option to the "connections" command
Charly COSTE <changaco@changaco.net>
parents: 168
diff changeset
205 parser.add_argument('--sort', '-s', default=False, action='store_true')
143
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
206 try:
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
207 args = parser.parse_args(args_array)
178
891195c47350 catch all exceptions in commands.py
Charly COSTE <changaco@changaco.net>
parents: 173
diff changeset
208 except Exception as e:
143
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
209 return '\n'+e.args[1]
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
210 n = len(bot.irc.connections)
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
211 if args.verbose:
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
212 ret = 'List of IRC connections ('+str(n)+'):'
173
6c4aaf8f3733 added "--sort" option to the "connections" command
Charly COSTE <changaco@changaco.net>
parents: 168
diff changeset
213 if args.sort:
6c4aaf8f3733 added "--sort" option to the "connections" command
Charly COSTE <changaco@changaco.net>
parents: 168
diff changeset
214 connections = [str(c) for c in bot.irc.connections]
6c4aaf8f3733 added "--sort" option to the "connections" command
Charly COSTE <changaco@changaco.net>
parents: 168
diff changeset
215 connections.sort()
6c4aaf8f3733 added "--sort" option to the "connections" command
Charly COSTE <changaco@changaco.net>
parents: 168
diff changeset
216 else:
6c4aaf8f3733 added "--sort" option to the "connections" command
Charly COSTE <changaco@changaco.net>
parents: 168
diff changeset
217 connections = bot.irc.connections
6c4aaf8f3733 added "--sort" option to the "connections" command
Charly COSTE <changaco@changaco.net>
parents: 168
diff changeset
218 for c in connections:
143
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
219 ret += '\n\t'+str(c)
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
220 else:
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
221 ret = 'Number of IRC connections: '+str(n)
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
222 return ret
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
223
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
224
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
225 def irc_participants(bot, command, args_array, bridge):
142
8c6184411ec7 minor fix in commands (unbound variable)
Charly COSTE <changaco@changaco.net>
parents: 134
diff changeset
226 ret = ''
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
227 if not bridge:
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
228 for b in bot.bridges:
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
229 irc_participants_nicknames = b.get_participants_nicknames_list(protocols=['irc'])
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
230 ret += '\nparticipants on '+b.irc_room+' at '+b.irc_server+' ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames)
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
231 return ret
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
232 else:
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
233 irc_participants_nicknames = bridge.get_participants_nicknames_list(protocols=['irc'])
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
234 return '\nparticipants on '+bridge.irc_room+' at '+bridge.irc_server+' ('+str(len(irc_participants_nicknames))+'): '+' '.join(irc_participants_nicknames)
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
235
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
236
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
237 def remove_bridges(bot, command, args_array, bridge):
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
238 parser = ArgumentParser(prog=command)
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
239 parser.add_argument('bridge_id', nargs='+')
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
240 try:
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
241 args = parser.parse_args(args_array)
178
891195c47350 catch all exceptions in commands.py
Charly COSTE <changaco@changaco.net>
parents: 173
diff changeset
242 except Exception as e:
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
243 return '\n'+e.args[1]
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
244
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
245 found_bridges, ret = _find_bridges(bot, args.bridge_id)
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
246
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
247 for found_bridge in found_bridges:
203
2a81c480439a renamed camelCased functions
Charly COSTE <changaco@changaco.net>
parents: 194
diff changeset
248 bot.remove_bridge(found_bridge)
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
249
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
250 return ret+'Bridges removed.'
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
251
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
252
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
253 def restart_bot(bot, command, args_array, bridge):
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
254 bot.restart()
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
255 return
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
256
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
257 def restart_bridges(bot, command, args_array, bridge):
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
258 parser = ArgumentParser(prog=command)
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
259 parser.add_argument('bridge_id', nargs='+')
239
70938f01be8f added a "--soft" option to the "restart-bridges" command
Charly COSTE <changaco@changaco.net>
parents: 227
diff changeset
260 parser.add_argument('--soft', default=False, action='store_true')
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
261 try:
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
262 args = parser.parse_args(args_array)
178
891195c47350 catch all exceptions in commands.py
Charly COSTE <changaco@changaco.net>
parents: 173
diff changeset
263 except Exception as e:
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
264 return '\n'+e.args[1]
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
265
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
266 found_bridges, ret = _find_bridges(bot, args.bridge_id)
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
267
239
70938f01be8f added a "--soft" option to the "restart-bridges" command
Charly COSTE <changaco@changaco.net>
parents: 227
diff changeset
268 if args.soft:
70938f01be8f added a "--soft" option to the "restart-bridges" command
Charly COSTE <changaco@changaco.net>
parents: 227
diff changeset
269 for found_bridge in found_bridges:
70938f01be8f added a "--soft" option to the "restart-bridges" command
Charly COSTE <changaco@changaco.net>
parents: 227
diff changeset
270 found_bridge.soft_restart()
70938f01be8f added a "--soft" option to the "restart-bridges" command
Charly COSTE <changaco@changaco.net>
parents: 227
diff changeset
271 return ret+'Bridges softly restarted.'
70938f01be8f added a "--soft" option to the "restart-bridges" command
Charly COSTE <changaco@changaco.net>
parents: 227
diff changeset
272
70938f01be8f added a "--soft" option to the "restart-bridges" command
Charly COSTE <changaco@changaco.net>
parents: 227
diff changeset
273 else:
70938f01be8f added a "--soft" option to the "restart-bridges" command
Charly COSTE <changaco@changaco.net>
parents: 227
diff changeset
274 for found_bridge in found_bridges:
70938f01be8f added a "--soft" option to the "restart-bridges" command
Charly COSTE <changaco@changaco.net>
parents: 227
diff changeset
275 found_bridge.restart()
70938f01be8f added a "--soft" option to the "restart-bridges" command
Charly COSTE <changaco@changaco.net>
parents: 227
diff changeset
276 return ret+'Bridges restarted.'
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
277
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
278
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
279 def stop_bot(bot, command, args_array, bridge):
157
ce0eb3e969a7 added a stop-bot command
Charly COSTE <changaco@changaco.net>
parents: 155
diff changeset
280 bot.stop()
194
5af6c828c606 minor fix to commands.py that I forgot to stage with the previous commit
Charly COSTE <changaco@changaco.net>
parents: 180
diff changeset
281 return
157
ce0eb3e969a7 added a stop-bot command
Charly COSTE <changaco@changaco.net>
parents: 155
diff changeset
282
ce0eb3e969a7 added a stop-bot command
Charly COSTE <changaco@changaco.net>
parents: 155
diff changeset
283
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
284 def stop_bridges(bot, command, args_array, bridge):
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
285 parser = ArgumentParser(prog=command)
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
286 parser.add_argument('bridge_id', nargs='+')
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
287 try:
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
288 args = parser.parse_args(args_array)
178
891195c47350 catch all exceptions in commands.py
Charly COSTE <changaco@changaco.net>
parents: 173
diff changeset
289 except Exception as e:
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
290 return '\n'+e.args[1]
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
291
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
292 found_bridges, ret = _find_bridges(bot, args.bridge_id)
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
293 for found_bridge in found_bridges:
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
294 found_bridge.stop()
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
295
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
296 return ret+'Bridges stopped.'
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
297
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
298
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
299 def xmpp_connections(bot, command, args_array, bridge):
143
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
300 parser = ArgumentParser(prog=command)
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
301 parser.add_argument('--verbose', '-v', default=False, action='store_true')
173
6c4aaf8f3733 added "--sort" option to the "connections" command
Charly COSTE <changaco@changaco.net>
parents: 168
diff changeset
302 parser.add_argument('--sort', '-s', default=False, action='store_true')
143
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
303 try:
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
304 args = parser.parse_args(args_array)
178
891195c47350 catch all exceptions in commands.py
Charly COSTE <changaco@changaco.net>
parents: 173
diff changeset
305 except Exception as e:
143
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
306 return '\n'+e.args[1]
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
307 n = len(bot.xmpp_connections)
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
308 if args.verbose:
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
309 ret = 'List of XMPP connections ('+str(n)+'):'
173
6c4aaf8f3733 added "--sort" option to the "connections" command
Charly COSTE <changaco@changaco.net>
parents: 168
diff changeset
310 nicknames = bot.xmpp_connections.keys()
6c4aaf8f3733 added "--sort" option to the "connections" command
Charly COSTE <changaco@changaco.net>
parents: 168
diff changeset
311 if args.sort:
6c4aaf8f3733 added "--sort" option to the "connections" command
Charly COSTE <changaco@changaco.net>
parents: 168
diff changeset
312 nicknames.sort()
6c4aaf8f3733 added "--sort" option to the "connections" command
Charly COSTE <changaco@changaco.net>
parents: 168
diff changeset
313 for nickname in nicknames:
143
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
314 ret += '\n\t'+nickname
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
315 else:
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
316 ret = 'Number of XMPP connections: '+str(n)
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
317 return ret
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
318
61d7cae1d15d added 3 commands: connections, irc-connections and xmpp-connections
Charly COSTE <changaco@changaco.net>
parents: 142
diff changeset
319
160
266a6afb6b79 changed the commands that modify bridges
Charly COSTE <changaco@changaco.net>
parents: 157
diff changeset
320 def xmpp_participants(bot, command, args_array, bridge):
142
8c6184411ec7 minor fix in commands (unbound variable)
Charly COSTE <changaco@changaco.net>
parents: 134
diff changeset
321 ret = ''
134
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
322 if not bridge:
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
323 for b in bot.bridges:
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
324 xmpp_participants_nicknames = b.get_participants_nicknames_list(protocols=['xmpp'])
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
325 ret += '\nparticipants on '+b.xmpp_room_jid+' ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames)
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
326 return ret
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
327 else:
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
328 xmpp_participants_nicknames = bridge.get_participants_nicknames_list(protocols=['xmpp'])
931a5edc7971 moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
329 return '\nparticipants on '+bridge.xmpp_room_jid+' ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames)