Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_text_commands.py @ 2689:d715d912afac
plugin XEP-0199: implementation of XMPP Ping
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 10 Nov 2018 10:16:38 +0100 |
parents | 56f94936df1e |
children | 003b8b4b56a7 |
comparison
equal
deleted
inserted
replaced
2688:943e78e18882 | 2689:d715d912afac |
---|---|
55 # FIXME: doc strings for commands have to be translatable | 55 # FIXME: doc strings for commands have to be translatable |
56 # plugins need a dynamic translation system (translation | 56 # plugins need a dynamic translation system (translation |
57 # should be downloadable independently) | 57 # should be downloadable independently) |
58 | 58 |
59 HELP_SUGGESTION = _( | 59 HELP_SUGGESTION = _( |
60 "Type '/help' to get a list of the available commands. If you didn't want to use a command, please start your message with '//' to escape the slash." | 60 u"Type '/help' to get a list of the available commands. If you didn't want to " |
61 u"use a command, please start your message with '//' to escape the slash." | |
61 ) | 62 ) |
62 | 63 |
63 def __init__(self, host): | 64 def __init__(self, host): |
64 log.info(_("Text commands initialization")) | 65 log.info(_("Text commands initialization")) |
65 self.host = host | 66 self.host = host |
73 """Parse a docstring to get text command data | 74 """Parse a docstring to get text command data |
74 | 75 |
75 @param cmd: function or method callback for the command, | 76 @param cmd: function or method callback for the command, |
76 its docstring will be used for self documentation in the following way: | 77 its docstring will be used for self documentation in the following way: |
77 - first line is the command short documentation, shown with /help | 78 - first line is the command short documentation, shown with /help |
78 - @command keyword can be used, see http://wiki.goffi.org/wiki/Coding_style/en for documentation | 79 - @command keyword can be used, |
80 see http://wiki.goffi.org/wiki/Coding_style/en for documentation | |
79 @return (dict): dictionary with parsed data where key can be: | 81 @return (dict): dictionary with parsed data where key can be: |
80 - "doc_short_help" (default: ""): the untranslated short documentation | 82 - "doc_short_help" (default: ""): the untranslated short documentation |
81 - "type" (default "all"): the command type as specified in documentation | 83 - "type" (default "all"): the command type as specified in documentation |
82 - "args" (default: ""): the arguments available, using syntax specified in documentation. | 84 - "args" (default: ""): the arguments available, using syntax specified in documentation. |
83 - "doc_arg_[name]": the doc of [name] argument | 85 - "doc_arg_[name]": the doc of [name] argument |
175 | 177 |
176 def addWhoIsCb(self, callback, priority=0): | 178 def addWhoIsCb(self, callback, priority=0): |
177 """Add a callback which give information to the /whois command | 179 """Add a callback which give information to the /whois command |
178 | 180 |
179 @param callback: a callback which will be called with the following arguments | 181 @param callback: a callback which will be called with the following arguments |
180 - whois_msg: list of information strings to display, callback need to append its own strings to it | 182 - whois_msg: list of information strings to display, callback need to append |
183 its own strings to it | |
181 - target_jid: full jid from whom we want information | 184 - target_jid: full jid from whom we want information |
182 - profile: %(doc_profile)s | 185 - profile: %(doc_profile)s |
183 @param priority: priority of the information to show (the highest priority will be displayed first) | 186 @param priority: priority of the information to show (the highest priority will |
187 be displayed first) | |
184 """ | 188 """ |
185 self._whois.append((priority, callback)) | 189 self._whois.append((priority, callback)) |
186 self._whois.sort(key=lambda item: item[0], reverse=True) | 190 self._whois.sort(key=lambda item: item[0], reverse=True) |
187 | 191 |
188 def sendMessageTrigger( | 192 def sendMessageTrigger( |
193 return True | 197 return True |
194 | 198 |
195 def _sendMessageCmdHook(self, mess_data, client): | 199 def _sendMessageCmdHook(self, mess_data, client): |
196 """ Check text commands in message, and react consequently | 200 """ Check text commands in message, and react consequently |
197 | 201 |
198 msg starting with / are potential command. If a command is found, it is executed, else and help message is sent | 202 msg starting with / are potential command. If a command is found, it is executed, |
203 else an help message is sent. | |
199 msg starting with // are escaped: they are sent with a single / | 204 msg starting with // are escaped: they are sent with a single / |
200 commands can abord message sending (if they return anything evaluating to False), or continue it (if they return True), eventually after modifying the message | 205 commands can abord message sending (if they return anything evaluating to False), |
201 an "unparsed" key is added to message, containing part of the message not yet parsed | 206 or continue it (if they return True), eventually after modifying the message |
202 commands can be deferred or not | 207 an "unparsed" key is added to message, containing part of the message not yet |
208 parsed. | |
209 Commands can be deferred or not | |
203 @param mess_data(dict): data comming from sendMessage trigger | 210 @param mess_data(dict): data comming from sendMessage trigger |
204 @param profile: %(doc_profile)s | 211 @param profile: %(doc_profile)s |
205 """ | 212 """ |
206 try: | 213 try: |
207 msg = mess_data["message"][""] | 214 msg = mess_data["message"][""] |