Mercurial > xib
annotate commands.py @ 142:8c6184411ec7
minor fix in commands (unbound variable)
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sun, 17 Jan 2010 11:41:56 +0100 |
parents | 931a5edc7971 |
children | 61d7cae1d15d |
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 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
25 from bridge import Bridge |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
26 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
27 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
28 commands = ['xmpp-participants', 'irc-participants', 'bridges'] |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
29 admin_commands = ['add-bridge', 'add-xmpp-admin', 'change-bridge-mode', 'halt', 'remove-bridge', 'restart-bot', 'restart-bridge', 'stop-bridge'] |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
30 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
31 def execute(bot, command_line, bot_admin, bridge): |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
32 ret = '' |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
33 command = shlex.split(command_line) |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
34 if len(command) > 1: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
35 args_array = command[1:] |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
36 else: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
37 args_array = [] |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
38 command = command[0] |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
39 command_func = command.replace('-', '_') |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
40 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
41 if not globals().has_key(command_func): |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
42 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
|
43 if bot_admin: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
44 return ret+'\n'+'admin commands: '+' '.join(admin_commands) |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
45 else: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
46 return ret |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
47 elif command in admin_commands and not bot_admin: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
48 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
|
49 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
50 b = bridge |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
51 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
52 if command in ['change-bridge-mode', 'remove-bridge', 'restart-bridge', 'stop-bridge']: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
53 # we need to know which bridge the command is for |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
54 if len(args_array) == 0: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
55 if bridge: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
56 b = bridge |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
57 else: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
58 return 'You must specify a bridge. '+bridges(bot, 'bridges', [], bot_admin, None) |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
59 else: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
60 try: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
61 bn = int(args_array[0]) |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
62 if bn < 1: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
63 raise IndexError |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
64 b = bot.bridges[bn-1] |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
65 except IndexError: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
66 return 'Invalid bridge number "'+str(bn)+'". '+bridges(bot, 'bridges', [], bot_admin, None) |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
67 except ValueError: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
68 bridges = bot.findBridges(args_array[0]) |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
69 if len(bridges) == 0: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
70 return 'No bridge found matching "'+args_array[0]+'". '+bridges(bot, 'bridges', [], bot_admin, None) |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
71 elif len(bridges) == 1: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
72 b = bridges[0] |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
73 elif len(bridges) > 1: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
74 return 'More than one bridge matches "'+args_array[0]+'", please be more specific. '+bridges(bot, 'bridges', [], bot_admin, None) |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
75 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
76 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
77 return globals()[command_func](bot, command, args_array, bot_admin, b) |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
78 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
79 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
80 def add_bridge(bot, command, args_array, bot_admin, bridge): |
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) |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
85 parser.add_argument('--mode', choices=Bridge._modes, default='normal') |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
86 parser.add_argument('--say-level', choices=Bridge._say_levels, default='all') |
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) |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
90 except ArgumentParser.ParseException as e: |
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 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
98 def add_xmpp_admin(bot, command, args_array, bot_admin, bridge): |
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) |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
101 try: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
102 args = parser.parse_args(args_array) |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
103 except ArgumentParser.ParseException as e: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
104 return '\n'+e.args[1] |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
105 bot.admins_jid.append(args.jid) |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
106 for b in bot.bridges: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
107 for p in b.participants: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
108 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
|
109 p.bot_admin = True |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
110 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
111 return 'XMPP admin added.' |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
112 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
113 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
114 def bridges(bot, command, args_array, bot_admin, bridge): |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
115 parser = ArgumentParser(prog=command) |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
116 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
|
117 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
|
118 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
|
119 try: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
120 args = parser.parse_args(args_array) |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
121 except ArgumentParser.ParseException as e: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
122 return '\n'+e.args[1] |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
123 ret = 'List of bridges:' |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
124 for i, b in enumerate(bot.bridges): |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
125 ret += '\n'+str(i+1)+' - '+str(b) |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
126 if args.show_mode: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
127 ret += ' - mode='+b.mode |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
128 if args.show_say_level: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
129 ret += ' - say_level='+Bridge._say_levels[b.say_level] |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
130 if args.show_participants: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
131 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
|
132 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
|
133 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
|
134 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
|
135 if b.irc_connection == None: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
136 ret += ' - this bridge is stopped, use "restart-bridge '+str(i+1)+'" to restart it' |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
137 return ret |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
138 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
139 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
140 def change_bridge_mode(bot, command, args_array, bot_admin, bridge): |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
141 new_mode = args_array[1] |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
142 if not new_mode in Bridge._modes: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
143 return '"'+new_mode+'" is not a valid mode, list of modes: '+' '.join(Bridge._modes) |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
144 r = bridge.changeMode(new_mode) |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
145 if r: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
146 return r |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
147 return 'Mode changed.' |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
148 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
149 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
150 def halt(bot, command, args_array, bot_admin, bridge): |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
151 bot.stop() |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
152 return |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
153 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
154 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
155 def irc_participants(bot, command, args_array, bot_admin, bridge): |
142
8c6184411ec7
minor fix in commands (unbound variable)
Charly COSTE <changaco@changaco.net>
parents:
134
diff
changeset
|
156 ret = '' |
134
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
157 if not bridge: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
158 for b in bot.bridges: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
159 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
|
160 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
|
161 return ret |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
162 else: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
163 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
|
164 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
|
165 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
166 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
167 def remove_bridge(bot, command, args_array, bot_admin, bridge): |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
168 bot.removeBridge(bridge) |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
169 return 'Bridge removed.' |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
170 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
171 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
172 def restart_bot(bot, command, args_array, bot_admin, bridge): |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
173 bot.restart() |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
174 return |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
175 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
176 def restart_bridge(bot, command, args_array, bot_admin, bridge): |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
177 bridge.restart() |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
178 return 'Bridge restarted.' |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
179 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
180 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
181 def stop_bridge(bot, command, args_array, bot_admin, bridge): |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
182 bridge.stop() |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
183 return 'Bridge stopped.' |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
184 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
185 |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
186 def xmpp_participants(bot, command, args_array, bot_admin, bridge): |
142
8c6184411ec7
minor fix in commands (unbound variable)
Charly COSTE <changaco@changaco.net>
parents:
134
diff
changeset
|
187 ret = '' |
134
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
188 if not bridge: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
189 for b in bot.bridges: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
190 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
|
191 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
|
192 return ret |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
193 else: |
931a5edc7971
moved commands to a separate file
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
194 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
|
195 return '\nparticipants on '+bridge.xmpp_room_jid+' ('+str(len(xmpp_participants_nicknames))+'): '+' '.join(xmpp_participants_nicknames) |