plugin XEP-0048: added /bookmark text command
This commit is contained in:
parent
63e668ec01
commit
bdd0673a9d
1 changed files with 32 additions and 6 deletions
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
from sat.core.i18n import _, D_
|
from sat.core.i18n import _, D_
|
||||||
from sat.core import exceptions
|
from sat.core import exceptions
|
||||||
|
from sat.core.constants import Const as C
|
||||||
from sat.memory.persistent import PersistentBinaryDict
|
from sat.memory.persistent import PersistentBinaryDict
|
||||||
from sat.tools import xml_tools
|
from sat.tools import xml_tools
|
||||||
from logging import debug, info, warning, error
|
from logging import debug, info, warning, error
|
||||||
|
|
@ -60,6 +61,10 @@ class XEP_0048(object):
|
||||||
self.private_plg = self.host.plugins["XEP-0049"]
|
self.private_plg = self.host.plugins["XEP-0049"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.private_plg = None
|
self.private_plg = None
|
||||||
|
try:
|
||||||
|
self.host.plugins[C.TEXT_CMDS].registerTextCommands(self)
|
||||||
|
except KeyError:
|
||||||
|
info(_("Text commands not available"))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def profileConnected(self, profile):
|
def profileConnected(self, profile):
|
||||||
|
|
@ -234,8 +239,9 @@ class XEP_0048(object):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def addBookmark(self, type_, location, data, storage_type="auto", profile_key="@NONE@"):
|
def addBookmark(self, type_, location, data, storage_type="auto", profile_key=C.PROF_KEY_NONE):
|
||||||
""" Store a new bookmark
|
"""Store a new bookmark
|
||||||
|
|
||||||
@param type_: bookmark type, one of:
|
@param type_: bookmark type, one of:
|
||||||
- XEP_0048.MUC_TYPE: Multi-User chat room
|
- XEP_0048.MUC_TYPE: Multi-User chat room
|
||||||
- XEP_0048.URL_TYPE: web page URL
|
- XEP_0048.URL_TYPE: web page URL
|
||||||
|
|
@ -251,7 +257,6 @@ class XEP_0048(object):
|
||||||
- "private": Private XML storage (XEP-0049)
|
- "private": Private XML storage (XEP-0049)
|
||||||
- "local": Store in SàT database
|
- "local": Store in SàT database
|
||||||
@param profile_key: %(doc_profile_key)s
|
@param profile_key: %(doc_profile_key)s
|
||||||
|
|
||||||
"""
|
"""
|
||||||
assert storage_type in ('auto', 'pubsub', 'private', 'local')
|
assert storage_type in ('auto', 'pubsub', 'private', 'local')
|
||||||
client = self.host.getClient(profile_key)
|
client = self.host.getClient(profile_key)
|
||||||
|
|
@ -274,7 +279,28 @@ class XEP_0048(object):
|
||||||
bookmark_elt = self._dict2BookmarkElt(type_, bookmarks)
|
bookmark_elt = self._dict2BookmarkElt(type_, bookmarks)
|
||||||
yield self._setServerBookmarks(storage_type, bookmark_elt, client.profile)
|
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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue