Mercurial > libervia-backend
changeset 983:c34e0b2bbf08
plugin XEP-0048: added /bookmark text command
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 07 Apr 2014 16:22:35 +0200 |
parents | 0e80ee1fe9af |
children | df8e1b557125 |
files | src/plugins/plugin_xep_0048.py |
diffstat | 1 files changed, 29 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0048.py Mon Apr 07 16:22:35 2014 +0200 +++ b/src/plugins/plugin_xep_0048.py Mon Apr 07 16:22:35 2014 +0200 @@ -19,6 +19,7 @@ from sat.core.i18n import _, D_ from sat.core import exceptions +from sat.core.constants import Const as C from sat.memory.persistent import PersistentBinaryDict from sat.tools import xml_tools from logging import debug, info, warning, error @@ -60,6 +61,10 @@ self.private_plg = self.host.plugins["XEP-0049"] except KeyError: self.private_plg = None + try: + self.host.plugins[C.TEXT_CMDS].registerTextCommands(self) + except KeyError: + info(_("Text commands not available")) @defer.inlineCallbacks def profileConnected(self, profile): @@ -234,8 +239,9 @@ return d @defer.inlineCallbacks - def addBookmark(self, type_, location, data, storage_type="auto", profile_key="@NONE@"): - """ Store a new bookmark + def addBookmark(self, type_, location, data, storage_type="auto", profile_key=C.PROF_KEY_NONE): + """Store a new bookmark + @param type_: bookmark type, one of: - XEP_0048.MUC_TYPE: Multi-User chat room - XEP_0048.URL_TYPE: web page URL @@ -251,7 +257,6 @@ - "private": Private XML storage (XEP-0049) - "local": Store in SàT database @param profile_key: %(doc_profile_key)s - """ assert storage_type in ('auto', 'pubsub', 'private', 'local') client = self.host.getClient(profile_key) @@ -274,7 +279,28 @@ bookmark_elt = self._dict2BookmarkElt(type_, bookmarks) yield self._setServerBookmarks(storage_type, bookmark_elt, client.profile) + def cmd_bookmark(self, mess_data, profile): + """Bookmark a MUC room + @command (group): [autojoin] + - autojoin: join room automatically on connection + """ + debug("Catched bookmark command") + client = self.host.getClient(profile) + txt_cmd = self.host.plugins[C.TEXT_CMDS] + if mess_data['type'] != "groupchat": + #/bookmark command does nothing if we are not on a group chat + info("Ignoring /bookmark command on a non groupchat message") + return True + options = mess_data["unparsed"].strip().split() + room_jid = mess_data["to"].userhostJID() + data = { "name": room_jid.user, + "nick": client.jid.user, + "autojoin": "true" if "autojoin" in options else "false", + } + self.addBookmark(XEP_0048.MUC_TYPE, room_jid, data, profile_key=profile) + txt_cmd.feedBack(_("Bookmark added"), mess_data, profile) + return False