annotate src/plugins/plugin_xep_0045.py @ 1955:633b5c21aefd

backend, frontend: messages refactoring (huge commit, not finished): /!\ database schema has been modified, do a backup before updating message have been refactored, here are the main changes: - languages are now handled - all messages have an uid (internal to SàT) - message updating is anticipated - subject is now first class - new naming scheme is used newMessage => messageNew, getHistory => historyGet, sendMessage => messageSend - minimal compatibility refactoring in quick_frontend/Primitivus, better refactoring should follow - threads handling - delayed messages are saved into history - info messages may also be saved in history (e.g. to keep track of people joining/leaving a room) - duplicate messages should be avoided - historyGet return messages in right order, no need to sort again - plugins have been updated to follow new features, some of them need to be reworked (e.g. OTR) - XEP-0203 (Delayed Delivery) is now fully handled in core, the plugin just handle disco and creation of a delay element - /!\ jp and Libervia are currently broken, as some features of Primitivus It has been put in one huge commit to avoid breaking messaging between changes. This is the main part of message refactoring, other commits will follow to take profit of the new features/behaviour.
author Goffi <goffi@goffi.org>
date Tue, 24 May 2016 22:11:04 +0200
parents 2daf7b4c6756
children a2bc5089c2eb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1934
2daf7b4c6756 use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents: 1891
diff changeset
1 #!/usr/bin/env python2
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
4 # SAT plugin for managing xep-0045
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1742
diff changeset
5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
10 # (at your option) any later version.
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
15 # GNU Affero General Public License for more details.
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 599
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
1068
1513511a0586 plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents: 1007
diff changeset
20 from sat.core.i18n import _, D_
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 811
diff changeset
21 from sat.core.constants import Const as C
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 950
diff changeset
22 from sat.core.log import getLogger
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 950
diff changeset
23 log = getLogger(__name__)
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
24 from twisted.internet import defer
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
25 from twisted.words.protocols.jabber import jid
505
2402668b5d05 plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents: 488
diff changeset
26
2402668b5d05 plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents: 488
diff changeset
27 from sat.core import exceptions
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
28 from sat.memory import memory
505
2402668b5d05 plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents: 488
diff changeset
29
319
5bb1cfc105d0 plugin xep-0045: misc improvments
Goffi <goffi@goffi.org>
parents: 291
diff changeset
30 import uuid
1239
b6dbac8ee485 plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents: 1199
diff changeset
31 import copy
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32
1466
2184d5f496b5 plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
33 from wokkel import muc, disco, iwokkel
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
34 from sat.tools import xml_tools
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35
1466
2184d5f496b5 plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
36 from zope.interface import implements
2184d5f496b5 plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
37
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 PLUGIN_INFO = {
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
40 "name": "XEP 0045 Plugin",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
41 "import_name": "XEP-0045",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
42 "type": "XEP",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
43 "protocols": ["XEP-0045"],
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
44 "dependencies": [],
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
45 "recommendations": [C.TEXT_CMDS],
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
46 "main": "XEP_0045",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
47 "handler": "yes",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
48 "description": _("""Implementation of Multi-User Chat""")
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 }
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50
1466
2184d5f496b5 plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
51 NS_MUC = 'http://jabber.org/protocol/muc'
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
52 AFFILIATIONS = ('owner', 'admin', 'member', 'none', 'outcast')
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
53
1407
77f07ea90420 plugin XEP-0045, quick_frontend, primitivus: replace C.DEFAULT_MUC by bridge method getDefaultMUC (value is defined in plugin XEP-0045 and can be overriden with the config file)
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
54 CONFIG_SECTION = u'plugin muc'
77f07ea90420 plugin XEP-0045, quick_frontend, primitivus: replace C.DEFAULT_MUC by bridge method getDefaultMUC (value is defined in plugin XEP-0045 and can be overriden with the config file)
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
55
77f07ea90420 plugin XEP-0045, quick_frontend, primitivus: replace C.DEFAULT_MUC by bridge method getDefaultMUC (value is defined in plugin XEP-0045 and can be overriden with the config file)
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
56 default_conf = {"default_muc": u'sat@chat.jabberfr.org'}
77f07ea90420 plugin XEP-0045, quick_frontend, primitivus: replace C.DEFAULT_MUC by bridge method getDefaultMUC (value is defined in plugin XEP-0045 and can be overriden with the config file)
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
57
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
58
505
2402668b5d05 plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents: 488
diff changeset
59 class UnknownRoom(Exception):
2402668b5d05 plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents: 488
diff changeset
60 pass
2402668b5d05 plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents: 488
diff changeset
61
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
62
1789
8e2c831073a6 plugin XEP-0045: raise a special error when the room has already been joined
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
63 class AlreadyJoinedRoom(Exception):
8e2c831073a6 plugin XEP-0045: raise a special error when the room has already been joined
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
64 pass
8e2c831073a6 plugin XEP-0045: raise a special error when the room has already been joined
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
65
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
66 class NotReadyYet(Exception):
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
67 pass
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
68
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
69
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
70 class XEP_0045(object):
928
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
71 # TODO: this plugin is messy, need a big cleanup/refactoring
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 950
diff changeset
74 log.info(_("Plugin XEP_0045 initialization"))
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 self.host = host
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
76 self.clients = {}
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
77 self._sessions = memory.Sessions()
1356
c01cbd8fc8dd plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents: 1315
diff changeset
78 host.bridge.addMethod("joinMUC", ".plugin", in_sign='ssa{ss}s', out_sign='s', method=self._join, async=True)
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
79 host.bridge.addMethod("mucNick", ".plugin", in_sign='sss', out_sign='', method=self.mucNick)
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
80 host.bridge.addMethod("mucLeave", ".plugin", in_sign='ss', out_sign='', method=self.mucLeave, async=True)
405
10b4f577d0c0 MUC update to follow wokkel's MUC branch update
Goffi <goffi@goffi.org>
parents: 372
diff changeset
81 host.bridge.addMethod("getRoomsJoined", ".plugin", in_sign='s', out_sign='a(sass)', method=self.getRoomsJoined)
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents: 409
diff changeset
82 host.bridge.addMethod("getRoomsSubjects", ".plugin", in_sign='s', out_sign='a(ss)', method=self.getRoomsSubjects)
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
83 host.bridge.addMethod("getUniqueRoomName", ".plugin", in_sign='ss', out_sign='s', method=self._getUniqueName)
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
84 host.bridge.addMethod("configureRoom", ".plugin", in_sign='ss', out_sign='s', method=self._configureRoom, async=True)
1407
77f07ea90420 plugin XEP-0045, quick_frontend, primitivus: replace C.DEFAULT_MUC by bridge method getDefaultMUC (value is defined in plugin XEP-0045 and can be overriden with the config file)
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
85 host.bridge.addMethod("getDefaultMUC", ".plugin", in_sign='', out_sign='s', method=self.getDefaultMUC)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
86 host.bridge.addSignal("roomJoined", ".plugin", signature='sasss') # args: room_jid, room_nicks, user_nick, profile
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
87 host.bridge.addSignal("roomLeft", ".plugin", signature='ss') # args: room_jid, profile
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
88 host.bridge.addSignal("roomUserJoined", ".plugin", signature='ssa{ss}s') # args: room_jid, user_nick, user_data, profile
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
89 host.bridge.addSignal("roomUserLeft", ".plugin", signature='ssa{ss}s') # args: room_jid, user_nick, user_data, profile
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
90 host.bridge.addSignal("roomUserChangedNick", ".plugin", signature='ssss') # args: room_jid, old_nick, new_nick, profile
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
91 host.bridge.addSignal("roomNewSubject", ".plugin", signature='sss') # args: room_jid, subject, profile
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
92 self.__submit_conf_id = host.registerCallback(self._submitConfiguration, with_data=True)
1538
55967cf161b1 reverted patch ad4ec8d9235e: there must not be security limit on room configuration
Goffi <goffi@goffi.org>
parents: 1466
diff changeset
93 host.importMenu((D_("MUC"), D_("configure")), self._configureRoomMenu, security_limit=0, help_string=D_("Configure Multi-User Chat room"), type_=C.MENU_ROOM)
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
94 try:
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
95 self.host.plugins[C.TEXT_CMDS].registerTextCommands(self)
928
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
96 self.host.plugins[C.TEXT_CMDS].addWhoIsCb(self._whois, 100)
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
97 except KeyError:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 950
diff changeset
98 log.info(_("Text commands not available"))
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
99
1239
b6dbac8ee485 plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents: 1199
diff changeset
100 host.trigger.add("presence_available", self.presenceTrigger)
b6dbac8ee485 plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents: 1199
diff changeset
101
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
102 def profileConnected(self, profile):
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
103 def assign_service(service):
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
104 client = self.host.getClient(profile)
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
105 client.muc_service = service
1552
e0bde0d0b321 core (disco): use of “profile” instead of “profile_key” in several disco methods
Goffi <goffi@goffi.org>
parents: 1538
diff changeset
106 return self.getMUCService(profile=profile).addCallback(assign_service)
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
107
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
108 def checkClient(self, profile):
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
109 """Check if the profile is connected and has used the MUC feature.
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
110
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
111 If profile was using MUC feature but is now disconnected, remove it from the client list.
75
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 74
diff changeset
112 @param profile: profile to check
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
113 @return: True if the profile is connected and has used the MUC feature, else False"""
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
114 if not profile or profile not in self.clients or not self.host.isConnected(profile):
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1407
diff changeset
115 log.error(_(u'Unknown or disconnected profile (%s)') % profile)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
116 if profile in self.clients:
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117 del self.clients[profile]
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118 return False
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
119 return True
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
120
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
121 def getProfileAssertInRoom(self, room_jid, profile_key):
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
122 """Retrieve the profile name, assert that it's connected and participating in the given room.
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
123
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
124 @param room_jid (JID): room JID
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
125 @param profile_key (str): %(doc_profile_key)
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
126 @return: the profile name
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
127 """
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
128 profile = self.host.memory.getProfileName(profile_key)
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
129 if not self.checkClient(profile):
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
130 raise exceptions.ProfileUnknownError("Unknown or disconnected profile")
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
131 if room_jid not in self.clients[profile].joined_rooms:
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
132 raise UnknownRoom("This room has not been joined")
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
133 return profile
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
134
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
135 def __room_joined(self, room, profile):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
136 """Called when the user is in the requested room"""
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
137
319
5bb1cfc105d0 plugin xep-0045: misc improvments
Goffi <goffi@goffi.org>
parents: 291
diff changeset
138 def _sendBridgeSignal(ignore=None):
405
10b4f577d0c0 MUC update to follow wokkel's MUC branch update
Goffi <goffi@goffi.org>
parents: 372
diff changeset
139 self.host.bridge.roomJoined(room.roomJID.userhost(), [user.nick for user in room.roster.values()], room.nick, profile)
319
5bb1cfc105d0 plugin xep-0045: misc improvments
Goffi <goffi@goffi.org>
parents: 291
diff changeset
140
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
141 self.clients[profile].joined_rooms[room.roomJID] = room
452
fd455b3ca6d4 plugin XEP-0045: room unlocking fix
Goffi <goffi@goffi.org>
parents: 451
diff changeset
142 if room.locked:
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
143 # FIXME: the current behaviour is to create an instant room
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
144 # and send the signal only when the room is unlocked
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
145 # a proper configuration management should be done
452
fd455b3ca6d4 plugin XEP-0045: room unlocking fix
Goffi <goffi@goffi.org>
parents: 451
diff changeset
146 print "room locked !"
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1407
diff changeset
147 self.clients[profile].configure(room.roomJID, {}).addCallbacks(_sendBridgeSignal, lambda x: log.error(_(u'Error while configuring the room')))
319
5bb1cfc105d0 plugin xep-0045: misc improvments
Goffi <goffi@goffi.org>
parents: 291
diff changeset
148 else:
5bb1cfc105d0 plugin xep-0045: misc improvments
Goffi <goffi@goffi.org>
parents: 291
diff changeset
149 _sendBridgeSignal()
5bb1cfc105d0 plugin xep-0045: misc improvments
Goffi <goffi@goffi.org>
parents: 291
diff changeset
150 return room
5bb1cfc105d0 plugin xep-0045: misc improvments
Goffi <goffi@goffi.org>
parents: 291
diff changeset
151
528
f899f6e2a9d1 plugin XEP-0045: in case of nickname conflict when entering a room, a new one is automaticaly assigned
Goffi <goffi@goffi.org>
parents: 522
diff changeset
152 def __err_joining_room(self, failure, room_jid, nick, history_options, password, profile):
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
153 """Called when something is going wrong when joining the room"""
712
f610864eb7a5 plugins (MUC, tools, games): generalize the generation of a unique room name when joining a MUC and no room is specified:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
154 if hasattr(failure.value, "condition") and failure.value.condition == 'conflict':
528
f899f6e2a9d1 plugin XEP-0045: in case of nickname conflict when entering a room, a new one is automaticaly assigned
Goffi <goffi@goffi.org>
parents: 522
diff changeset
155 # we have a nickname conflict, we try again with "_" suffixed to current nickname
f899f6e2a9d1 plugin XEP-0045: in case of nickname conflict when entering a room, a new one is automaticaly assigned
Goffi <goffi@goffi.org>
parents: 522
diff changeset
156 nick += '_'
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
157 return self.clients[profile].join(room_jid, nick, history_options, password).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile': profile}, errbackArgs=[room_jid, nick, history_options, password, profile])
1068
1513511a0586 plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents: 1007
diff changeset
158 mess = D_("Error while joining the room %s" % room_jid.userhost())
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
159 try:
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
160 mess += " with condition '%s'" % failure.value.condition
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
161 except AttributeError:
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
162 pass
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 950
diff changeset
163 log.error(mess)
1068
1513511a0586 plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents: 1007
diff changeset
164 self.host.bridge.newAlert(mess, D_("Group chat error"), "ERROR", profile)
450
afe9cfd2ddbb plugins: radio collective first draft
Goffi <goffi@goffi.org>
parents: 409
diff changeset
165 raise failure
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
166
1392
c7082457d03f memory, plugin XEP-0045: getMainResource returns None when asking a MUC entity + fixes /whois on a MUC (bare) entity
souliane <souliane@mailoo.org>
parents: 1384
diff changeset
167 def isRoom(self, entity_bare, profile_key):
c7082457d03f memory, plugin XEP-0045: getMainResource returns None when asking a MUC entity + fixes /whois on a MUC (bare) entity
souliane <souliane@mailoo.org>
parents: 1384
diff changeset
168 """Tell if a bare entity is a MUC room.
c7082457d03f memory, plugin XEP-0045: getMainResource returns None when asking a MUC entity + fixes /whois on a MUC (bare) entity
souliane <souliane@mailoo.org>
parents: 1384
diff changeset
169
c7082457d03f memory, plugin XEP-0045: getMainResource returns None when asking a MUC entity + fixes /whois on a MUC (bare) entity
souliane <souliane@mailoo.org>
parents: 1384
diff changeset
170 @param entity_bare (jid.JID): bare entity
c7082457d03f memory, plugin XEP-0045: getMainResource returns None when asking a MUC entity + fixes /whois on a MUC (bare) entity
souliane <souliane@mailoo.org>
parents: 1384
diff changeset
171 @param profile_key (unicode): %(doc_profile_key)s
c7082457d03f memory, plugin XEP-0045: getMainResource returns None when asking a MUC entity + fixes /whois on a MUC (bare) entity
souliane <souliane@mailoo.org>
parents: 1384
diff changeset
172 @return bool
c7082457d03f memory, plugin XEP-0045: getMainResource returns None when asking a MUC entity + fixes /whois on a MUC (bare) entity
souliane <souliane@mailoo.org>
parents: 1384
diff changeset
173 """
c7082457d03f memory, plugin XEP-0045: getMainResource returns None when asking a MUC entity + fixes /whois on a MUC (bare) entity
souliane <souliane@mailoo.org>
parents: 1384
diff changeset
174 profile = self.host.memory.getProfileName(profile_key)
c7082457d03f memory, plugin XEP-0045: getMainResource returns None when asking a MUC entity + fixes /whois on a MUC (bare) entity
souliane <souliane@mailoo.org>
parents: 1384
diff changeset
175 return entity_bare in self.clients[profile].joined_rooms
c7082457d03f memory, plugin XEP-0045: getMainResource returns None when asking a MUC entity + fixes /whois on a MUC (bare) entity
souliane <souliane@mailoo.org>
parents: 1384
diff changeset
176
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 811
diff changeset
177 def getRoomsJoined(self, profile_key=C.PROF_KEY_NONE):
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
178 """Return room where user is"""
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
179 profile = self.host.memory.getProfileName(profile_key)
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
180 result = []
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
181 if not self.checkClient(profile):
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
182 return result
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
183 for room in self.clients[profile].joined_rooms.values():
405
10b4f577d0c0 MUC update to follow wokkel's MUC branch update
Goffi <goffi@goffi.org>
parents: 372
diff changeset
184 result.append((room.roomJID.userhost(), [user.nick for user in room.roster.values()], room.nick))
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
185 return result
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
186
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
187 def getRoomNick(self, room_jid, profile_key=C.PROF_KEY_NONE):
93
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 91
diff changeset
188 """return nick used in room by user
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
189
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
190 @param room_jid (jid.JID): JID of the room
93
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 91
diff changeset
191 @profile_key: profile
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 91
diff changeset
192 @return: nick or empty string in case of error"""
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 91
diff changeset
193 profile = self.host.memory.getProfileName(profile_key)
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
194 if not self.checkClient(profile) or room_jid not in self.clients[profile].joined_rooms:
93
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 91
diff changeset
195 return ''
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
196 return self.clients[profile].joined_rooms[room_jid].nick
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
197
715
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
198 def getRoomNickOfUser(self, room, user_jid, secure=True):
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
199 """Returns the nick of the given user in the room.
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
200
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
201 @param room (wokkel.muc.Room): the room
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
202 @param user (jid.JID): bare JID of the user
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
203 @param secure (bool): set to True for a secure check
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
204 @return: unicode or None if the user didn't join the room.
715
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
205 """
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
206 for user in room.roster.values():
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
207 if user.entity is not None:
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
208 if user.entity.userhostJID() == user_jid.userhostJID():
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
209 return user.nick
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
210 elif not secure:
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
211 # FIXME: this is NOT ENOUGH to check an identity!!
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
212 # See in which conditions user.entity could be None.
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
213 if user.nick == user_jid.user:
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
214 return user.nick
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
215 return None
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
216
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
217 def getRoomNicksOfUsers(self, room, users=[], secure=True):
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
218 """Returns the nicks of the given users in the room.
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
219
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
220 @param room (wokkel.muc.Room): the room
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
221 @param users (list[jid.JID]): list of users
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
222 @param secure (True): set to True for a secure check
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
223 @return: a couple (x, y) with:
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
224 - x (list[unicode]): nicks of the users who are in the room
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
225 - y (list[jid.JID]): JID of the missing users.
715
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
226 """
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
227 nicks = []
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
228 missing = []
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
229 for user in users:
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
230 nick = self.getRoomNickOfUser(room, user, secure)
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
231 if nick is None:
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
232 missing.append(user)
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
233 else:
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
234 nicks.append(nick)
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
235 return nicks, missing
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
236
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 811
diff changeset
237 def _configureRoom(self, room_jid_s, profile_key=C.PROF_KEY_NONE):
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
238 d = self.configureRoom(jid.JID(room_jid_s), profile_key)
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
239 d.addCallback(lambda xmlui: xmlui.toXml())
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
240 return d
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
241
1094
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
242 def _configureRoomMenu(self, menu_data, profile):
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
243 """Return room configuration form
1135
3158f9e08760 plugin OTR: a warning is logged when Account is instancied with a bare jid.
Goffi <goffi@goffi.org>
parents: 1101
diff changeset
244
1094
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
245 @param menu_data: %(menu_data)s
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
246 @param profile: %(doc_profile)s
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
247 """
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
248 try:
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
249 room_jid = jid.JID(menu_data['room_jid'])
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
250 except KeyError:
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
251 log.error(_("room_jid key is not present !"))
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
252 return defer.fail(exceptions.DataError)
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
253
1094
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
254 def xmluiReceived(xmlui):
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
255 return {"xmlui": xmlui.toXml()}
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
256 return self.configureRoom(room_jid, profile).addCallback(xmluiReceived)
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
257
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 811
diff changeset
258 def configureRoom(self, room_jid, profile_key=C.PROF_KEY_NONE):
1094
4286a19e9e8a pluging XEP-0045: configure room dynamic menu
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
259 """return the room configuration form
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
260
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
261 @param room: jid of the room to configure
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
262 @param profile_key: %(doc_profile_key)s
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
263 @return: configuration form as XMLUI
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
264 """
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
265 profile = self.getProfileAssertInRoom(room_jid, profile_key)
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
266
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
267 def config2XMLUI(result):
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
268 if not result:
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
269 return ""
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
270 session_id, session_data = self._sessions.newSession(profile=profile)
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
271 session_data["room_jid"] = room_jid
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
272 xmlui = xml_tools.dataForm2XMLUI(result, submit_id=self.__submit_conf_id)
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
273 xmlui.session_id = session_id
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
274 return xmlui
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
275
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
276 d = self.clients[profile].getConfiguration(room_jid)
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
277 d.addCallback(config2XMLUI)
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
278 return d
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
279
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
280 def _submitConfiguration(self, raw_data, profile):
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
281 try:
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
282 session_data = self._sessions.profileGet(raw_data["session_id"], profile)
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
283 except KeyError:
1068
1513511a0586 plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents: 1007
diff changeset
284 log.warning(D_("Session ID doesn't exist, session has probably expired."))
1513511a0586 plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents: 1007
diff changeset
285 _dialog = xml_tools.XMLUI('popup', title=D_('Room configuration failed'))
1513511a0586 plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents: 1007
diff changeset
286 _dialog.addText(D_("Session ID doesn't exist, session has probably expired."))
1513511a0586 plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents: 1007
diff changeset
287 return defer.succeed({'xmlui': _dialog.toXml()})
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
288
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
289 data = xml_tools.XMLUIResult2DataFormResult(raw_data)
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
290 d = self.clients[profile].configure(session_data['room_jid'], data)
1068
1513511a0586 plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents: 1007
diff changeset
291 _dialog = xml_tools.XMLUI('popup', title=D_('Room configuration succeed'))
1513511a0586 plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents: 1007
diff changeset
292 _dialog.addText(D_("The new settings have been saved."))
1513511a0586 plugin XEP-0045: room configuration returns a success or failure message
souliane <souliane@mailoo.org>
parents: 1007
diff changeset
293 d.addCallback(lambda ignore: {'xmlui': _dialog.toXml()})
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
294 del self._sessions[raw_data["session_id"]]
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
295 return d
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 791
diff changeset
296
522
3446ce33247d plugin XEP-0045: added isNickInRoom method
Goffi <goffi@goffi.org>
parents: 519
diff changeset
297 def isNickInRoom(self, room_jid, nick, profile):
3446ce33247d plugin XEP-0045: added isNickInRoom method
Goffi <goffi@goffi.org>
parents: 519
diff changeset
298 """Tell if a nick is currently present in a room"""
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
299 profile = self.getProfileAssertInRoom(room_jid, profile)
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
300 return self.clients[profile].joined_rooms[room_jid].inRoster(muc.User(nick))
93
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 91
diff changeset
301
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 811
diff changeset
302 def getRoomsSubjects(self, profile_key=C.PROF_KEY_NONE):
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
303 """Return received subjects of rooms"""
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
304 profile = self.host.memory.getProfileName(profile_key)
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
305 if not self.checkClient(profile):
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
306 return []
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
307 return self.clients[profile].rec_subjects.values()
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
308
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
309 @defer.inlineCallbacks
1552
e0bde0d0b321 core (disco): use of “profile” instead of “profile_key” in several disco methods
Goffi <goffi@goffi.org>
parents: 1538
diff changeset
310 def getMUCService(self, jid_=None, profile=C.PROF_KEY_NONE):
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
311 """Return first found MUC service of an entity
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
312
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
313 @param jid_: entity which may have a MUC service, or None for our own server
1552
e0bde0d0b321 core (disco): use of “profile” instead of “profile_key” in several disco methods
Goffi <goffi@goffi.org>
parents: 1538
diff changeset
314 @param profile: %(doc_profile)s
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
315 """
712
f610864eb7a5 plugins (MUC, tools, games): generalize the generation of a unique room name when joining a MUC and no room is specified:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
316 muc_service = None
1552
e0bde0d0b321 core (disco): use of “profile” instead of “profile_key” in several disco methods
Goffi <goffi@goffi.org>
parents: 1538
diff changeset
317 services = yield self.host.findServiceEntities("conference", "text", jid_, profile=profile)
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
318 for service in services:
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
319 if ".irc." not in service.userhost():
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
320 # FIXME:
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
321 # This ugly hack is here to avoid an issue with openfire: the IRC gateway
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
322 # use "conference/text" identity (instead of "conference/irc")
712
f610864eb7a5 plugins (MUC, tools, games): generalize the generation of a unique room name when joining a MUC and no room is specified:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
323 muc_service = service
f610864eb7a5 plugins (MUC, tools, games): generalize the generation of a unique room name when joining a MUC and no room is specified:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
324 break
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
325 defer.returnValue(muc_service)
712
f610864eb7a5 plugins (MUC, tools, games): generalize the generation of a unique room name when joining a MUC and no room is specified:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
326
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
327 def _getUniqueName(self, muc_service="", profile_key=C.PROF_KEY_NONE):
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
328 return self.getUniqueName(muc_service or None, profile_key).full()
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
329
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
330 def getUniqueName(self, muc_service=None, profile_key=C.PROF_KEY_NONE):
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
331 """Return unique name for a room, avoiding collision
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
332
1356
c01cbd8fc8dd plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents: 1315
diff changeset
333 @param muc_service (jid.JID) : leave empty string to use the default service
c01cbd8fc8dd plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents: 1315
diff changeset
334 @return: jid.JID (unique room bare JID)
712
f610864eb7a5 plugins (MUC, tools, games): generalize the generation of a unique room name when joining a MUC and no room is specified:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
335 """
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
336 # TODO: we should use #RFC-0045 10.1.4 when available here
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
337 client = self.host.getClient(profile_key)
712
f610864eb7a5 plugins (MUC, tools, games): generalize the generation of a unique room name when joining a MUC and no room is specified:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
338 room_name = uuid.uuid1()
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
339 if muc_service is None:
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
340 try:
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
341 muc_service = client.muc_service
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
342 except AttributeError:
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
343 raise NotReadyYet("Main server MUC service has not been checked yet")
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
344 if muc_service is None:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 950
diff changeset
345 log.warning(_("No MUC service found on main server"))
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
346 raise exceptions.FeatureNotFound
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
347
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
348 muc_service = muc_service.userhost()
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 928
diff changeset
349 return jid.JID("%s@%s" % (room_name, muc_service))
319
5bb1cfc105d0 plugin xep-0045: misc improvments
Goffi <goffi@goffi.org>
parents: 291
diff changeset
350
1407
77f07ea90420 plugin XEP-0045, quick_frontend, primitivus: replace C.DEFAULT_MUC by bridge method getDefaultMUC (value is defined in plugin XEP-0045 and can be overriden with the config file)
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
351 def getDefaultMUC(self):
77f07ea90420 plugin XEP-0045, quick_frontend, primitivus: replace C.DEFAULT_MUC by bridge method getDefaultMUC (value is defined in plugin XEP-0045 and can be overriden with the config file)
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
352 """Return the default MUC.
77f07ea90420 plugin XEP-0045, quick_frontend, primitivus: replace C.DEFAULT_MUC by bridge method getDefaultMUC (value is defined in plugin XEP-0045 and can be overriden with the config file)
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
353
77f07ea90420 plugin XEP-0045, quick_frontend, primitivus: replace C.DEFAULT_MUC by bridge method getDefaultMUC (value is defined in plugin XEP-0045 and can be overriden with the config file)
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
354 @return: unicode
77f07ea90420 plugin XEP-0045, quick_frontend, primitivus: replace C.DEFAULT_MUC by bridge method getDefaultMUC (value is defined in plugin XEP-0045 and can be overriden with the config file)
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
355 """
77f07ea90420 plugin XEP-0045, quick_frontend, primitivus: replace C.DEFAULT_MUC by bridge method getDefaultMUC (value is defined in plugin XEP-0045 and can be overriden with the config file)
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
356 return self.host.memory.getConfig(CONFIG_SECTION, 'default_muc', default_conf['default_muc'])
77f07ea90420 plugin XEP-0045, quick_frontend, primitivus: replace C.DEFAULT_MUC by bridge method getDefaultMUC (value is defined in plugin XEP-0045 and can be overriden with the config file)
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
357
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 811
diff changeset
358 def join(self, room_jid, nick, options, profile_key=C.PROF_KEY_NONE):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
359 def _errDeferred(exc_obj=Exception, txt='Error while joining room'):
350
abe08fcb42d7 plugin XEP-0045: added error callback to join's deferred, and a callback is created if join fail before calling MUCClient's join
Goffi <goffi@goffi.org>
parents: 319
diff changeset
360 d = defer.Deferred()
abe08fcb42d7 plugin XEP-0045: added error callback to join's deferred, and a callback is created if join fail before calling MUCClient's join
Goffi <goffi@goffi.org>
parents: 319
diff changeset
361 d.errback(exc_obj(txt))
451
4f196e2d3781 plugin xep-0045: fixed missing return deferred
Goffi <goffi@goffi.org>
parents: 450
diff changeset
362 return d
350
abe08fcb42d7 plugin XEP-0045: added error callback to join's deferred, and a callback is created if join fail before calling MUCClient's join
Goffi <goffi@goffi.org>
parents: 319
diff changeset
363
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
364 profile = self.host.memory.getProfileName(profile_key)
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
365 if not self.checkClient(profile):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
366 return _errDeferred()
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
367 if room_jid in self.clients[profile].joined_rooms:
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1407
diff changeset
368 log.warning(_(u'%(profile)s is already in room %(room_jid)s') % {'profile': profile, 'room_jid': room_jid.userhost()})
1789
8e2c831073a6 plugin XEP-0045: raise a special error when the room has already been joined
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
369 return _errDeferred(AlreadyJoinedRoom, D_(u"The room has already been joined"))
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1407
diff changeset
370 log.info(_(u"[%(profile)s] is joining room %(room)s with nick %(nick)s") % {'profile': profile, 'room': room_jid.userhost(), 'nick': nick})
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
371
1256
4b27b9bf31b0 plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents: 1250
diff changeset
372 if "history" in options:
4b27b9bf31b0 plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents: 1250
diff changeset
373 history_limit = int(options["history"])
4b27b9bf31b0 plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents: 1250
diff changeset
374 else:
4b27b9bf31b0 plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents: 1250
diff changeset
375 history_limit = int(self.host.memory.getParamA(C.HISTORY_LIMIT, 'General', profile_key=profile))
4b27b9bf31b0 plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents: 1250
diff changeset
376 # http://xmpp.org/extensions/xep-0045.html#enter-managehistory
4b27b9bf31b0 plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents: 1250
diff changeset
377 history_options = muc.HistoryOptions(maxStanzas=history_limit)
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
378 password = options["password"] if "password" in options else None
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
379
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
380 return self.clients[profile].join(room_jid, nick, history_options, password).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile': profile}, errbackArgs=[room_jid, nick, history_options, password, profile])
743
5a131930348d plugin XEP-0045: remove redondant errback from _join
souliane <souliane@mailoo.org>
parents: 742
diff changeset
381 # FIXME: how to set the cancel method on the Deferred created by wokkel?
5a131930348d plugin XEP-0045: remove redondant errback from _join
souliane <souliane@mailoo.org>
parents: 742
diff changeset
382 # This happens when the room is not reachable, e.g. no internet connection:
5a131930348d plugin XEP-0045: remove redondant errback from _join
souliane <souliane@mailoo.org>
parents: 742
diff changeset
383 # > /usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py(480)_startRunCallbacks()
5a131930348d plugin XEP-0045: remove redondant errback from _join
souliane <souliane@mailoo.org>
parents: 742
diff changeset
384 # -> raise AlreadyCalledError(extra)
405
10b4f577d0c0 MUC update to follow wokkel's MUC branch update
Goffi <goffi@goffi.org>
parents: 372
diff changeset
385
1700
0502a1fbe8b5 plugin XEP-0045: fixed bad default parameter
Goffi <goffi@goffi.org>
parents: 1552
diff changeset
386 def _join(self, room_jid_s, nick, options=None, profile_key=C.PROF_KEY_NONE):
743
5a131930348d plugin XEP-0045: remove redondant errback from _join
souliane <souliane@mailoo.org>
parents: 742
diff changeset
387 """join method used by bridge: use the join method, but doesn't return any deferred
1356
c01cbd8fc8dd plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents: 1315
diff changeset
388 @return: unicode (the room bare)
712
f610864eb7a5 plugins (MUC, tools, games): generalize the generation of a unique room name when joining a MUC and no room is specified:
souliane <souliane@mailoo.org>
parents: 609
diff changeset
389 """
1700
0502a1fbe8b5 plugin XEP-0045: fixed bad default parameter
Goffi <goffi@goffi.org>
parents: 1552
diff changeset
390 if options is None:
0502a1fbe8b5 plugin XEP-0045: fixed bad default parameter
Goffi <goffi@goffi.org>
parents: 1552
diff changeset
391 options = {}
406
b03b38b20c18 plugin XEP-0045: send error on invalid room jid on _join
Goffi <goffi@goffi.org>
parents: 405
diff changeset
392 profile = self.host.memory.getProfileName(profile_key)
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
393 if not self.checkClient(profile):
406
b03b38b20c18 plugin XEP-0045: send error on invalid room jid on _join
Goffi <goffi@goffi.org>
parents: 405
diff changeset
394 return
1356
c01cbd8fc8dd plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents: 1315
diff changeset
395 if room_jid_s:
1384
73f8582c7c99 plugins XEP-0045, XEP-0249: allow to join / invite without specifying the JID's host part (use client's values)
souliane <souliane@mailoo.org>
parents: 1381
diff changeset
396 muc_service = self.host.getClient(profile).muc_service
1356
c01cbd8fc8dd plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents: 1315
diff changeset
397 try:
c01cbd8fc8dd plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents: 1315
diff changeset
398 room_jid = jid.JID(room_jid_s)
c01cbd8fc8dd plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents: 1315
diff changeset
399 except (RuntimeError, jid.InvalidFormat, AttributeError):
1384
73f8582c7c99 plugins XEP-0045, XEP-0249: allow to join / invite without specifying the JID's host part (use client's values)
souliane <souliane@mailoo.org>
parents: 1381
diff changeset
400 return defer.fail(jid.InvalidFormat(_(u"Invalid room identifier: '%s'. Please give a room short or full identifier like 'room' or 'room@%s'.") % (room_jid_s, unicode(muc_service))))
73f8582c7c99 plugins XEP-0045, XEP-0249: allow to join / invite without specifying the JID's host part (use client's values)
souliane <souliane@mailoo.org>
parents: 1381
diff changeset
401 if not room_jid.user:
73f8582c7c99 plugins XEP-0045, XEP-0249: allow to join / invite without specifying the JID's host part (use client's values)
souliane <souliane@mailoo.org>
parents: 1381
diff changeset
402 room_jid.user, room_jid.host = room_jid.host, muc_service
1356
c01cbd8fc8dd plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents: 1315
diff changeset
403 else:
c01cbd8fc8dd plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents: 1315
diff changeset
404 room_jid = self.getUniqueName(profile_key=profile_key)
743
5a131930348d plugin XEP-0045: remove redondant errback from _join
souliane <souliane@mailoo.org>
parents: 742
diff changeset
405 # TODO: error management + signal in bridge
1356
c01cbd8fc8dd plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents: 1315
diff changeset
406 d = self.join(room_jid, nick, options, profile)
c01cbd8fc8dd plugin XEP-0045: make joinMUC asynchronous and fixes its handler
souliane <souliane@mailoo.org>
parents: 1315
diff changeset
407 return d.addCallback(lambda room: room.roomJID.userhost())
505
2402668b5d05 plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents: 488
diff changeset
408
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
409 def nick(self, room_jid, nick, profile_key):
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
410 profile = self.getProfileAssertInRoom(room_jid, profile_key)
505
2402668b5d05 plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents: 488
diff changeset
411 return self.clients[profile].nick(room_jid, nick)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
412
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
413 def leave(self, room_jid, profile_key):
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
414 profile = self.getProfileAssertInRoom(room_jid, profile_key)
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
415 return self.clients[profile].leave(room_jid)
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
416
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
417 def subject(self, room_jid, subject, profile_key):
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
418 profile = self.getProfileAssertInRoom(room_jid, profile_key)
515
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
419 return self.clients[profile].subject(room_jid, subject)
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
420
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 811
diff changeset
421 def mucNick(self, room_jid_s, nick, profile_key=C.PROF_KEY_NONE):
505
2402668b5d05 plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents: 488
diff changeset
422 """Change nickname in a room"""
2402668b5d05 plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents: 488
diff changeset
423 return self.nick(jid.JID(room_jid_s), nick, profile_key)
2402668b5d05 plugin xep-0045: nick change management
Goffi <goffi@goffi.org>
parents: 488
diff changeset
424
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 811
diff changeset
425 def mucLeave(self, room_jid_s, profile_key=C.PROF_KEY_NONE):
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
426 """Leave a room"""
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
427 return self.leave(jid.JID(room_jid_s), profile_key)
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
428
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
429 def getHandler(self, profile):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
430 self.clients[profile] = SatMUCClient(self)
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
431 return self.clients[profile]
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
432
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
433 def profileDisconnected(self, profile):
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
434 try:
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
435 del self.clients[profile]
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
436 except KeyError:
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
437 pass
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
438
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
439 def kick(self, nick, room_jid, options={}, profile_key=C.PROF_KEY_NONE):
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
440 """
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
441 Kick a participant from the room
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
442 @param nick (str): nick of the user to kick
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
443 @param room_jid_s (JID): jid of the room
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
444 @param options (dict): attribute with extra info (reason, password) as in #XEP-0045
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
445 @param profile_key (str): %(doc_profile_key)s
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
446 """
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
447 profile = self.getProfileAssertInRoom(room_jid, profile_key)
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
448 return self.clients[profile].kick(room_jid, nick, reason=options.get('reason', None))
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
449
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
450 def ban(self, entity_jid, room_jid, options={}, profile_key=C.PROF_KEY_NONE):
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
451 """
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
452 Ban an entity from the room
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
453 @param entity_jid (JID): bare jid of the entity to be banned
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
454 @param room_jid_s (JID): jid of the room
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
455 @param options: attribute with extra info (reason, password) as in #XEP-0045
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
456 @param profile_key (str): %(doc_profile_key)s
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
457 """
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
458 assert(not entity_jid.resource)
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
459 assert(not room_jid.resource)
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
460 profile = self.getProfileAssertInRoom(room_jid, profile_key)
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
461 return self.clients[profile].ban(room_jid, entity_jid, reason=options.get('reason', None))
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
462
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
463 def affiliate(self, entity_jid, room_jid, options=None, profile_key=C.PROF_KEY_NONE):
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
464 """
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
465 Change the affiliation of an entity
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
466 @param entity_jid (JID): bare jid of the entity
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
467 @param room_jid_s (JID): jid of the room
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
468 @param options: attribute with extra info (reason, nick) as in #XEP-0045
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
469 @param profile_key (str): %(doc_profile_key)s
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
470 """
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
471 assert(not entity_jid.resource)
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
472 assert(not room_jid.resource)
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
473 assert('affiliation' in options)
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
474 profile = self.getProfileAssertInRoom(room_jid, profile_key)
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
475 # TODO: handles reason and nick
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
476 return self.clients[profile].modifyAffiliationList(room_jid, [entity_jid], options['affiliation'])
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
477
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
478 # Text commands #
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
479
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
480 def cmd_nick(self, mess_data, profile):
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
481 """change nickname
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
482
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
483 @command (group): new_nick
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
484 - new_nick: new nick to use
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
485 """
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
486 nick = mess_data["unparsed"].strip()
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
487 if nick:
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
488 room = mess_data["to"]
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
489 self.nick(room, nick, profile)
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
490
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
491 return False
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
492
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
493 def cmd_join(self, mess_data, profile):
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
494 """join a new room
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
495
1381
0d12d4e32664 plugin XEP-0045: /join text command can be used in all contexts, not only group
Goffi <goffi@goffi.org>
parents: 1371
diff changeset
496 @command (all): JID
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
497 - JID: room to join (on the same service if full jid is not specified)
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
498 """
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
499 if mess_data["unparsed"].strip():
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
500 room_jid = self.host.plugins[C.TEXT_CMDS].getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host)
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
501 nick = (self.getRoomNick(room_jid, profile) or
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
502 self.host.getClient(profile).jid.user)
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
503 self.join(room_jid, nick, {}, profile)
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
504
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
505 return False
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
506
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
507 def cmd_leave(self, mess_data, profile):
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
508 """quit a room
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
509
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
510 @command (group): [ROOM_JID]
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
511 - ROOM_JID: jid of the room to live (current room if not specified)
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
512 """
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
513 if mess_data["unparsed"].strip():
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
514 room = self.host.plugins[C.TEXT_CMDS].getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host)
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
515 else:
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
516 room = mess_data["to"]
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
517
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
518 self.leave(room, profile)
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
519
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
520 return False
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
521
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
522 def cmd_part(self, mess_data, profile):
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
523 """just a synonym of /leave
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
524
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
525 @command (group): [ROOM_JID]
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
526 - ROOM_JID: jid of the room to live (current room if not specified)
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
527 """
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
528 return self.cmd_leave(mess_data, profile)
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
529
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
530 def cmd_kick(self, mess_data, profile):
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
531 """kick a room member
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
532
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
533 @command (group): ROOM_NICK
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
534 - ROOM_NICK: the nick of the person to kick
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
535 """
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
536 options = mess_data["unparsed"].strip().split()
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
537 try:
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
538 nick = options[0]
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
539 assert(self.isNickInRoom(mess_data["to"], nick, profile))
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
540 except (IndexError, AssertionError):
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
541 feedback = _(u"You must provide a member's nick to kick.")
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
542 self.host.plugins[C.TEXT_CMDS].feedBack(feedback, mess_data, profile)
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
543 return False
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
544
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
545 d = self.kick(nick, mess_data["to"], {} if len(options) == 1 else {'reason': options[1]}, profile)
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
546
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
547 def cb(dummy):
1890
0a45bc8e7cf4 plugin XEP-0045: fixed feedback for /kick /ban and /afficiliate commands which should not be public
Goffi <goffi@goffi.org>
parents: 1789
diff changeset
548 feedback_msg = _(u'You have kicked {}').format(nick)
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
549 if len(options) > 1:
1890
0a45bc8e7cf4 plugin XEP-0045: fixed feedback for /kick /ban and /afficiliate commands which should not be public
Goffi <goffi@goffi.org>
parents: 1789
diff changeset
550 feedback_msg += _(u' for the following reason: {}').format(options[1])
0a45bc8e7cf4 plugin XEP-0045: fixed feedback for /kick /ban and /afficiliate commands which should not be public
Goffi <goffi@goffi.org>
parents: 1789
diff changeset
551 self.host.plugins[C.TEXT_CMDS].feedBack(feedback_msg, mess_data, profile)
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
552 return True
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
553 d.addCallback(cb)
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
554 return d
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
555
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
556 def cmd_ban(self, mess_data, profile):
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
557 """ban an entity from the room
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
558
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
559 @command (group): (JID) [reason]
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
560 - JID: the JID of the entity to ban
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
561 - reason: the reason why this entity is being banned
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
562 """
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
563 options = mess_data["unparsed"].strip().split()
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
564 try:
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
565 jid_s = options[0]
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
566 entity_jid = jid.JID(jid_s).userhostJID()
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
567 assert(entity_jid.user)
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
568 assert(entity_jid.host)
1742
244a605623d6 complete the Exception's list when catching JID error:
souliane <souliane@mailoo.org>
parents: 1700
diff changeset
569 except (RuntimeError, jid.InvalidFormat, AttributeError, IndexError, AssertionError):
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
570 feedback = _(u"You must provide a valid JID to ban, like in '/ban contact@example.net'")
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
571 self.host.plugins[C.TEXT_CMDS].feedBack(feedback, mess_data, profile)
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
572 return False
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
573
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
574 d = self.ban(entity_jid, mess_data["to"], {} if len(options) == 1 else {'reason': options[1]}, profile)
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
575
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
576 def cb(dummy):
1890
0a45bc8e7cf4 plugin XEP-0045: fixed feedback for /kick /ban and /afficiliate commands which should not be public
Goffi <goffi@goffi.org>
parents: 1789
diff changeset
577 feedback_msg = _(u'You have banned {}').format(entity_jid)
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
578 if len(options) > 1:
1890
0a45bc8e7cf4 plugin XEP-0045: fixed feedback for /kick /ban and /afficiliate commands which should not be public
Goffi <goffi@goffi.org>
parents: 1789
diff changeset
579 feedback_msg += _(u' for the following reason: {}').format(options[1])
0a45bc8e7cf4 plugin XEP-0045: fixed feedback for /kick /ban and /afficiliate commands which should not be public
Goffi <goffi@goffi.org>
parents: 1789
diff changeset
580 self.host.plugins[C.TEXT_CMDS].feedBack(feedback_msg, mess_data, profile)
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
581 return True
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
582 d.addCallback(cb)
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
583 return d
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
584
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
585 def cmd_affiliate(self, mess_data, profile):
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
586 """affiliate an entity to the room
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
587
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
588 @command (group): (JID) [owner|admin|member|none|outcast]
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
589 - JID: the JID of the entity to affiliate
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
590 - owner: grant owner privileges
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
591 - admin: grant admin privileges
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
592 - member: grant member privileges
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
593 - none: reset entity privileges
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
594 - outcast: ban entity
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
595 """
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
596 options = mess_data["unparsed"].strip().split()
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
597 try:
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
598 jid_s = options[0]
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
599 entity_jid = jid.JID(jid_s).userhostJID()
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
600 assert(entity_jid.user)
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
601 assert(entity_jid.host)
1742
244a605623d6 complete the Exception's list when catching JID error:
souliane <souliane@mailoo.org>
parents: 1700
diff changeset
602 except (RuntimeError, jid.InvalidFormat, AttributeError, IndexError, AssertionError):
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
603 feedback = _(u"You must provide a valid JID to affiliate, like in '/affiliate contact@example.net member'")
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
604 self.host.plugins[C.TEXT_CMDS].feedBack(feedback, mess_data, profile)
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
605 return False
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
606
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
607 affiliation = options[1] if len(options) > 1 else 'none'
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
608 if affiliation not in AFFILIATIONS:
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
609 feedback = _(u"You must provide a valid affiliation: %s") % ' '.join(AFFILIATIONS)
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
610 self.host.plugins[C.TEXT_CMDS].feedBack(feedback, mess_data, profile)
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
611 return False
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
612
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
613 d = self.affiliate(entity_jid, mess_data["to"], {'affiliation': affiliation}, profile)
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
614
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
615 def cb(dummy):
1890
0a45bc8e7cf4 plugin XEP-0045: fixed feedback for /kick /ban and /afficiliate commands which should not be public
Goffi <goffi@goffi.org>
parents: 1789
diff changeset
616 feedback_msg = _(u'New affiliation for %(entity)s: %(affiliation)s').format(entity=entity_jid, affiliation=affiliation)
0a45bc8e7cf4 plugin XEP-0045: fixed feedback for /kick /ban and /afficiliate commands which should not be public
Goffi <goffi@goffi.org>
parents: 1789
diff changeset
617 self.host.plugins[C.TEXT_CMDS].feedBack(feedback_msg, mess_data, profile)
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
618 return True
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
619 d.addCallback(cb)
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
620 return d
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
621
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
622 def cmd_title(self, mess_data, profile):
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
623 """change room's subject
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
624
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
625 @command (group): title
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
626 - title: new room subject
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
627 """
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
628 subject = mess_data["unparsed"].strip()
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
629
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
630 if subject:
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
631 room = mess_data["to"]
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
632 self.subject(room, subject, profile)
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
633
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
634 return False
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
635
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
636 def cmd_topic(self, mess_data, profile):
1371
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
637 """just a synonym of /title
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
638
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
639 @command (group): title
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
640 - title: new room subject
876c9fbd0b3d plugin text command, XEP-0045, XEP-0048, XEP-0249: removed feedBackWrongContext which is no more usefull with new _contextValid method
Goffi <goffi@goffi.org>
parents: 1358
diff changeset
641 """
926
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
642 return self.cmd_title(mess_data, profile)
d609581bf74a plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
643
928
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
644 def _whois(self, whois_msg, mess_data, target_jid, profile):
1199
96fb74a4714d misc: fixed some typos
Matteo Cypriani <mcy@lm7.fr>
parents: 1135
diff changeset
645 """ Add MUC user information to whois """
928
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
646 if mess_data['type'] != "groupchat":
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
647 return
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
648 if target_jid.userhostJID() not in self.clients[profile].joined_rooms:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 950
diff changeset
649 log.warning(_("This room has not been joined"))
928
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
650 return
1392
c7082457d03f memory, plugin XEP-0045: getMainResource returns None when asking a MUC entity + fixes /whois on a MUC (bare) entity
souliane <souliane@mailoo.org>
parents: 1384
diff changeset
651 if not target_jid.resource:
c7082457d03f memory, plugin XEP-0045: getMainResource returns None when asking a MUC entity + fixes /whois on a MUC (bare) entity
souliane <souliane@mailoo.org>
parents: 1384
diff changeset
652 return
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
653 user = self.clients[profile].joined_rooms[target_jid.userhostJID()].getUser(target_jid.resource)
928
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
654 whois_msg.append(_("Nickname: %s") % user.nick)
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
655 if user.entity:
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
656 whois_msg.append(_("Entity: %s") % user.entity)
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
657 if user.affiliation != 'none':
928
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
658 whois_msg.append(_("Affiliation: %s") % user.affiliation)
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
659 if user.role != 'none':
928
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
660 whois_msg.append(_("Role: %s") % user.role)
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
661 if user.status:
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
662 whois_msg.append(_("Status: %s") % user.status)
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
663 if user.show:
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
664 whois_msg.append(_("Show: %s") % user.show)
73873e9b56f7 plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents: 926
diff changeset
665
1239
b6dbac8ee485 plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents: 1199
diff changeset
666 def presenceTrigger(self, presence_elt, client):
b6dbac8ee485 plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents: 1199
diff changeset
667 # XXX: shouldn't it be done by the server ?!!
b6dbac8ee485 plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents: 1199
diff changeset
668 muc_client = self.clients[client.profile]
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
669 for room_jid, room in muc_client.joined_rooms.iteritems():
1239
b6dbac8ee485 plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents: 1199
diff changeset
670 elt = copy.deepcopy(presence_elt)
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
671 elt['to'] = room_jid.userhost() + '/' + room.nick
1239
b6dbac8ee485 plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents: 1199
diff changeset
672 client.presence.send(elt)
b6dbac8ee485 plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents: 1199
diff changeset
673 return True
b6dbac8ee485 plugin XEP-0045: handle MUC presence
souliane <souliane@mailoo.org>
parents: 1199
diff changeset
674
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
675
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
676 class SatMUCClient (muc.MUCClient):
1466
2184d5f496b5 plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
677 implements(iwokkel.IDisco)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
678
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
679 def __init__(self, plugin_parent):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
680 self.plugin_parent = plugin_parent
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
681 self.host = plugin_parent.host
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
682 muc.MUCClient.__init__(self)
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 77
diff changeset
683 self.rec_subjects = {}
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
684 self.__changing_nicks = set() # used to keep trace of who is changing nick,
1083
e8731b02f5ea plugin XEP-0045: small refactorization + clean on profile's disconnection
souliane <souliane@mailoo.org>
parents: 1082
diff changeset
685 # and to discard userJoinedRoom signal in this case
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
686 print "init SatMUCClient OK"
515
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
687
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
688 @property
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
689 def joined_rooms(self):
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
690 return self._rooms
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
691
515
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
692 def subject(self, room, subject):
29b5ef129488 plugin XEP-0045, plugin text commands: added '/title' command
Goffi <goffi@goffi.org>
parents: 509
diff changeset
693 return muc.MUCClientProtocol.subject(self, room, subject)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
694
1891
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
695 def availableReceived(self, presence):
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
696 """
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
697 Available presence was received.
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
698 """
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
699 # XXX: we override MUCClient.availableReceived to fix bugs
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
700 # (affiliation and role are not set)
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
701 # FIXME: propose a patch upstream
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
702
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
703 room, user = self._getRoomUser(presence)
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
704
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
705 if room is None:
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
706 return
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
707
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
708 if user is None:
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
709 nick = presence.sender.resource
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
710 user = muc.User(nick, presence.entity)
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
711
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
712 # Update user data
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
713 user.role = presence.role
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
714 user.affiliation = presence.affiliation
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
715 user.status = presence.status
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
716 user.show = presence.show
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
717
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
718 if room.inRoster(user):
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
719 self.userUpdatedStatus(room, user, presence.show, presence.status)
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
720 else:
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
721 room.addUser(user)
b91c8637c656 plugin XEP-0045: overriden availableReceived method of MUCClient to work around a bug in Wokkel (affiliation and role are not set). TODO: propose a patch upstream
Goffi <goffi@goffi.org>
parents: 1890
diff changeset
722 self.userJoinedRoom(room, user)
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
723 def unavailableReceived(self, presence):
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
724 # XXX: we override this method to manage nickname change
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
725 # TODO: feed this back to Wokkel
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
726 """
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
727 Unavailable presence was received.
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
728
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
729 If this was received from a MUC room occupant JID, that occupant has
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
730 left the room.
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
731 """
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
732 room, user = self._getRoomUser(presence)
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
733
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
734 if room is None or user is None:
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
735 return
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
736
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
737 room.removeUser(user)
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
738
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
739 if muc.STATUS_CODE.NEW_NICK in presence.mucStatuses:
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
740 self.__changing_nicks.add(presence.nick)
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
741 self.userChangedNick(room, user, presence.nick)
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
742 else:
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
743 self.__changing_nicks.discard(presence.nick)
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
744 self.userLeftRoom(room, user)
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
745
74
6e3a06b4dd36 plugin xep-0045: added roomUserJoined and roomUserLeft signals
Goffi <goffi@goffi.org>
parents: 73
diff changeset
746 def userJoinedRoom(self, room, user):
1315
be3a301540c0 core (memory): updateEntityData now accept a "silent" argument to avoid sending signal to frontends when updating an attribute with "signalOnUpdate" flag.
Goffi <goffi@goffi.org>
parents: 1256
diff changeset
747 self.host.memory.updateEntityData(room.roomJID, "type", "chatroom", profile_key=self.parent.profile)
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
748 if user.nick in self.__changing_nicks:
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
749 self.__changing_nicks.remove(user.nick)
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
750 else:
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1407
diff changeset
751 log.debug(_(u"user %(nick)s has joined room (%(room_id)s)") % {'nick': user.nick, 'room_id': room.occupantJID.userhost()})
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
752 if not self.host.trigger.point("MUC user joined", room, user, self.parent.profile):
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
753 return
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
754 user_data = {'entity': user.entity.full() if user.entity else '', 'affiliation': user.affiliation, 'role': user.role}
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
755 self.host.bridge.roomUserJoined(room.roomJID.userhost(), user.nick, user_data, self.parent.profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
756
74
6e3a06b4dd36 plugin xep-0045: added roomUserJoined and roomUserLeft signals
Goffi <goffi@goffi.org>
parents: 73
diff changeset
757 def userLeftRoom(self, room, user):
715
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
758 if not self.host.trigger.point("MUC user left", room, user, self.parent.profile):
f47d7c09c60b plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
souliane <souliane@mailoo.org>
parents: 713
diff changeset
759 return
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
760 if user.nick == room.nick:
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
761 # we left the room
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
762 room_jid_s = room.roomJID.userhost()
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1407
diff changeset
763 log.info(_(u"Room [%(room)s] left (%(profile)s))") % {"room": room_jid_s,
1358
bf3f669a6052 plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents: 1356
diff changeset
764 "profile": self.parent.profile})
1082
246712d2e7bc plugin XEP-0045, text_commands: add some commands:
souliane <souliane@mailoo.org>
parents: 1068
diff changeset
765 self.host.memory.delEntityCache(room.roomJID, profile_key=self.parent.profile)
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
766 self.host.bridge.roomLeft(room.roomJID.userhost(), self.parent.profile)
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
767 else:
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1407
diff changeset
768 log.debug(_(u"user %(nick)s left room (%(room_id)s)") % {'nick': user.nick, 'room_id': room.occupantJID.userhost()})
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
769 user_data = {'entity': user.entity.full() if user.entity else '', 'affiliation': user.affiliation, 'role': user.role}
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
770 self.host.bridge.roomUserLeft(room.roomJID.userhost(), user.nick, user_data, self.parent.profile)
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
771
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 505
diff changeset
772 def userChangedNick(self, room, user, new_nick):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
773 self.host.bridge.roomUserChangedNick(room.roomJID.userhost(), user.nick, new_nick, self.parent.profile)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
774
77
1ae680f9682e wix: MUC groupchat management + short nick shown in chat window instead of full jid when possible
Goffi <goffi@goffi.org>
parents: 76
diff changeset
775 def userUpdatedStatus(self, room, user, show, status):
1417
176de79c8c39 core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
776 self.host.bridge.presenceUpdate(room.roomJID.userhost() + '/' + user.nick, show or '', 0, {C.PRESENCE_STATUSES_DEFAULT: status or ''}, self.parent.profile)
77
1ae680f9682e wix: MUC groupchat management + short nick shown in chat window instead of full jid when possible
Goffi <goffi@goffi.org>
parents: 76
diff changeset
777
1256
4b27b9bf31b0 plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents: 1250
diff changeset
778 def receivedGroupChat(self, room, user, body):
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1407
diff changeset
779 log.debug(u'receivedGroupChat: room=%s user=%s body=%s' % (room.roomJID.full(), user, body))
1256
4b27b9bf31b0 plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents: 1250
diff changeset
780
4b27b9bf31b0 plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents: 1250
diff changeset
781 def receivedHistory(self, room, user, message):
4b27b9bf31b0 plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents: 1250
diff changeset
782 # http://xmpp.org/extensions/xep-0045.html#enter-history
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1407
diff changeset
783 # log.debug(u'receivedHistory: room=%s user=%s body=%s' % (room.roomJID.full(), user, message))
1256
4b27b9bf31b0 plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents: 1250
diff changeset
784 pass
4b27b9bf31b0 plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents: 1250
diff changeset
785
405
10b4f577d0c0 MUC update to follow wokkel's MUC branch update
Goffi <goffi@goffi.org>
parents: 372
diff changeset
786 def receivedSubject(self, room, user, subject):
1256
4b27b9bf31b0 plugin XEP-0045: use HISTORY_LIMIT param to retrieve the MUC history
souliane <souliane@mailoo.org>
parents: 1250
diff changeset
787 # http://xmpp.org/extensions/xep-0045.html#enter-subject
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1407
diff changeset
788 log.debug(_(u"New subject for room (%(room_id)s): %(subject)s") % {'room_id': room.roomJID.full(), 'subject': subject})
405
10b4f577d0c0 MUC update to follow wokkel's MUC branch update
Goffi <goffi@goffi.org>
parents: 372
diff changeset
789 self.rec_subjects[room.roomJID.userhost()] = (room.roomJID.userhost(), subject)
10b4f577d0c0 MUC update to follow wokkel's MUC branch update
Goffi <goffi@goffi.org>
parents: 372
diff changeset
790 self.host.bridge.roomNewSubject(room.roomJID.userhost(), subject, self.parent.profile)
1466
2184d5f496b5 plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
791
2184d5f496b5 plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
792 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
2184d5f496b5 plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
793 return [disco.DiscoFeature(NS_MUC)]
2184d5f496b5 plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
794
2184d5f496b5 plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
795 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
2184d5f496b5 plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
796 # TODO: manage room queries ? Bad for privacy, must be disabled by default
2184d5f496b5 plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
797 # see XEP-0045 § 6.7
2184d5f496b5 plugin XEP-0045: added disco announce
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
798 return []