Mercurial > libervia-backend
comparison src/plugins/plugin_misc_text_commands.py @ 517:59b32c04e105
plugin text commands: added /help command
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 20 Oct 2012 19:22:51 +0200 |
parents | 29b5ef129488 |
children | 75216d94a89d |
comparison
equal
deleted
inserted
replaced
516:7ee15fbe8c08 | 517:59b32c04e105 |
---|---|
32 "handler": "no", | 32 "handler": "no", |
33 "description": _("""IRC like text commands""") | 33 "description": _("""IRC like text commands""") |
34 } | 34 } |
35 | 35 |
36 class TextCommands(): | 36 class TextCommands(): |
37 #FIXME: doc strings for commands have to be translatable | |
38 # plugins need a dynamic translation system (translation | |
39 # should be downloadable independently) | |
37 | 40 |
38 def __init__(self, host): | 41 def __init__(self, host): |
39 info(_("Text commands initialization")) | 42 info(_("Text commands initialization")) |
40 self.host = host | 43 self.host = host |
41 host.trigger.add("sendMessage", self.sendMessageTrigger) | 44 host.trigger.add("sendMessage", self.sendMessageTrigger) |
73 return jid.JID(arg) | 76 return jid.JID(arg) |
74 return jid.JID(arg+service_jid) | 77 return jid.JID(arg+service_jid) |
75 return jid.JID(u"%s@%s" % (arg, service_jid)) | 78 return jid.JID(u"%s@%s" % (arg, service_jid)) |
76 | 79 |
77 def cmd_nick(self, mess_data, profile): | 80 def cmd_nick(self, mess_data, profile): |
81 """change nickname""" | |
78 debug("Catched nick command") | 82 debug("Catched nick command") |
79 | 83 |
80 if mess_data['type'] != "groupchat": | 84 if mess_data['type'] != "groupchat": |
81 #/nick command does nothing if we are not on a group chat | 85 #/nick command does nothing if we are not on a group chat |
82 info("Ignoring /nick command on a non groupchat message") | 86 info("Ignoring /nick command on a non groupchat message") |
89 self.host.plugins["XEP-0045"].nick(room,nick,profile) | 93 self.host.plugins["XEP-0045"].nick(room,nick,profile) |
90 | 94 |
91 return False | 95 return False |
92 | 96 |
93 def cmd_join(self, mess_data, profile): | 97 def cmd_join(self, mess_data, profile): |
98 """join a new room (on the same service if full jid is not specified)""" | |
94 debug("Catched join command") | 99 debug("Catched join command") |
95 | 100 |
96 if mess_data['type'] != "groupchat": | 101 if mess_data['type'] != "groupchat": |
97 #/leave command does nothing if we are not on a group chat | 102 #/leave command does nothing if we are not on a group chat |
98 info("Ignoring /join command on a non groupchat message") | 103 info("Ignoring /join command on a non groupchat message") |
105 self.host.plugins["XEP-0045"].join(room, nick, {}, profile) | 110 self.host.plugins["XEP-0045"].join(room, nick, {}, profile) |
106 | 111 |
107 return False | 112 return False |
108 | 113 |
109 def cmd_leave(self, mess_data, profile): | 114 def cmd_leave(self, mess_data, profile): |
115 """quit a room""" | |
110 debug("Catched leave command") | 116 debug("Catched leave command") |
111 | 117 |
112 if mess_data['type'] != "groupchat": | 118 if mess_data['type'] != "groupchat": |
113 #/leave command does nothing if we are not on a group chat | 119 #/leave command does nothing if we are not on a group chat |
114 info("Ignoring /leave command on a non groupchat message") | 120 info("Ignoring /leave command on a non groupchat message") |
126 def cmd_part(self, mess_data, profile): | 132 def cmd_part(self, mess_data, profile): |
127 """just a synonym of /leave""" | 133 """just a synonym of /leave""" |
128 return self.cmd_leave(mess_data, profile) | 134 return self.cmd_leave(mess_data, profile) |
129 | 135 |
130 def cmd_title(self, mess_data, profile): | 136 def cmd_title(self, mess_data, profile): |
137 """Change room's subject""" | |
131 debug("Catched title command") | 138 debug("Catched title command") |
132 | 139 |
133 if mess_data['type'] != "groupchat": | 140 if mess_data['type'] != "groupchat": |
134 #/leave command does nothing if we are not on a group chat | 141 #/leave command does nothing if we are not on a group chat |
135 info("Ignoring /title command on a non groupchat message") | 142 info("Ignoring /title command on a non groupchat message") |
141 room = mess_data["to"] | 148 room = mess_data["to"] |
142 self.host.plugins["XEP-0045"].subject(room, subject, profile) | 149 self.host.plugins["XEP-0045"].subject(room, subject, profile) |
143 | 150 |
144 return False | 151 return False |
145 | 152 |
153 def cmd_help(self, mess_data, profile): | |
154 """show help on available commands""" | |
155 commands=filter(lambda method: method.startswith('cmd_'), dir(self)) | |
156 longuest = max([len(command) for command in commands]) | |
157 help_cmds = [] | |
158 | |
159 for command in commands: | |
160 method = getattr(self, command) | |
161 try: | |
162 help_str = method.__doc__.split('\n')[0] | |
163 except AttributeError: | |
164 help_str = '' | |
165 spaces = (longuest - len(command)) * ' ' | |
166 help_cmds.append(" /%s: %s %s" % (command[4:], spaces, help_str)) | |
167 | |
168 if mess_data["type"] == 'groupchat': | |
169 _from = mess_data["to"].userhostJID() | |
170 else: | |
171 _from = self.host.getJidNStream(profile)[0] | |
172 | |
173 help_mess = _(u"Text commands available:\n%s") % (u'\n'.join(help_cmds),) | |
174 | |
175 self.host.bridge.newMessage(unicode(mess_data["to"]), help_mess, mess_data['type'], unicode(_from), {}, profile=profile) | |
176 | |
177 | |
178 |