""" Slixmpp: The Slick XMPP Library Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout This file is part of Slixmpp. See the file LICENSE for copying permission. """ from slixmpp.plugins import BasePlugin, register_plugin class XEP_0302(BasePlugin): name = "xep_0302" description = "XEP-0302: XMPP Compliance Suites 2012" dependencies = set(["xep_0030", "xep_0115", "xep_0054", "xep_0163", "xep_0045", "xep_0085", "xep_0184", "xep_0198"]) register_plugin(XEP_0302)
'get-active-users-num', 'get-idle-users-num', 'get-registered-users-list', 'get-disabled-users-list', 'get-online-users-list', 'get-online-users', 'get-active-users', 'get-idle-userslist', 'announce', 'set-motd', 'edit-motd', 'delete-motd', 'set-welcome', 'delete-welcome', 'edit-admin', 'restart', 'shutdown']) def get_commands(self, jid=None, **kwargs): if jid is None: jid = self.xmpp.boundjid.server return self.xmpp['xep_0050'].get_commands(jid, **kwargs) def create_command(name): def admin_command(self, jid=None, session=None, ifrom=None): if jid is None: jid = self.xmpp.boundjid.server self.xmpp['xep_0050'].start_command( jid=jid, node='http://jabber.org/protocol/admin#%s' % name, session=session, ifrom=ifrom) return admin_command for cmd in XEP_0133.commands: setattr(XEP_0133, cmd.replace('-', '_'), create_command(cmd)) register_plugin(XEP_0133)
the XMPP. Also see <http://www.xmpp.org/extensions/xep-0082.html>. Methods: date -- Create a time stamp using the Date profile. datetime -- Create a time stamp using the DateTime profile. time -- Create a time stamp using the Time profile. format_date -- Format an existing date object. format_datetime -- Format an existing datetime object. format_time -- Format an existing time object. parse -- Convert a time string into a Python datetime object. """ name = 'xep_0082' description = 'XEP-0082: XMPP Date and Time Profiles' dependencies = set() def plugin_init(self): """Start the XEP-0082 plugin.""" self.date = date self.datetime = datetime self.time = time self.format_date = format_date self.format_datetime = format_datetime self.format_time = format_time self.parse = parse register_plugin(XEP_0082)
def _reset_presence_activity(self, e): self._initial_presence = set() def _initial_presence_activity(self, stanza): if isinstance(stanza, Presence): use_last_activity = False if self.auto_last_activity and stanza['show'] in ('xa', 'away'): use_last_activity = True if stanza['from'] not in self._initial_presence: self._initial_presence.add(stanza['from']) use_last_activity = True if use_last_activity: plugin = self.xmpp['xep_0012'] try: result = plugin.api['get_last_activity'](stanza['from'], None, stanza['to']) seconds = result['last_activity']['seconds'] except XMPPError: seconds = None if seconds is not None: stanza['last_activity']['seconds'] = seconds return stanza register_plugin(XEP_0256)
self.redis.hset( '%s:session:%s:%s' % (self.key_prefix, self.current_ballot, jid.bare), 'votes', json.dumps(votes)) self.redis.hset( '%s:session:%s:%s' % (self.key_prefix, self.current_ballot, jid.bare), 'fulfilled', json.dumps(fulfilled)) return self.get_session(jid) def abstain_vote(self, jid, section, item): session = self.get_session(jid) votes = session['votes'] if item in votes[section]: del votes[section][item] fulfilled = session['fulfilled'] fulfilled[section] = sum( [1 for (name, vote) in votes[section].items() if vote == 'yes']) self.redis.hset( '%s:session:%s:%s' % (self.key_prefix, self.current_ballot, jid.bare), 'votes', json.dumps(votes)) self.redis.hset( '%s:session:%s:%s' % (self.key_prefix, self.current_ballot, jid.bare), 'fulfilled', json.dumps(fulfilled)) return self.get_session(jid) register_plugin(XSFVoting)
# Slixmpp: The Slick XMPP Library # Copyright (C) 2020 "Maxime “pep” Buquet <*****@*****.**>" # This file is part of Slixmpp. # See the file LICENSE for copying permission. from slixmpp.plugins import register_plugin from slixmpp.plugins.xep_0045 import stanza from slixmpp.plugins.xep_0045.muc import XEP_0045 from slixmpp.plugins.xep_0045.stanza import MUCPresence, MUCMessage register_plugin(XEP_0045)
""" Slixmpp: The Slick XMPP Library Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout This file is part of Slixmpp. See the file LICENSE for copying permission. """ from slixmpp.plugins import BasePlugin, register_plugin class XEP_0106(BasePlugin): name = 'xep_0106' description = 'XEP-0106: JID Escaping' dependencies = {'xep_0030'} def session_bind(self, jid): self.xmpp['xep_0030'].add_feature(feature='jid\\20escaping') def plugin_end(self): self.xmpp['xep_0030'].del_feature(feature='jid\\20escaping') register_plugin(XEP_0106)
""" Slixmpp: The Slick XMPP Library Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout This file is part of Slixmpp. See the file LICENSE for copying permission. """ from slixmpp.plugins import BasePlugin, register_plugin class XEP_0242(BasePlugin): name = 'xep_0242' description = 'XEP-0242: XMPP Client Compliance 2009' dependencies = set([ 'xep_0030', 'xep_0115', 'xep_0054', 'xep_0045', 'xep_0085', 'xep_0016', 'xep_0191' ]) register_plugin(XEP_0242)
""" Slixmpp: The Slick XMPP Library Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout This file is part of Slixmpp. See the file LICENSE for copying permission. """ from slixmpp.plugins import BasePlugin, register_plugin class XEP_0270(BasePlugin): name = 'xep_0270' description = 'XEP-0270: XMPP Compliance Suites 2010' dependencies = set(['xep_0030', 'xep_0115', 'xep_0054', 'xep_0163', 'xep_0045', 'xep_0085']) register_plugin(XEP_0270)
self.xmpp.register_feature('compression', self._handle_compression, restart=True, order=self.config.get('order', 5)) def register_compression_method(self, name, handler): self.compression_methods[name] = handler def _handle_compression(self, features): for method in features['compression']['methods']: if method in self.compression_methods: log.info('Attempting to use %s compression' % method) c = Compress(self.xmpp) c['method'] = method c.send(now=True) return True return False def _handle_compressed(self, stanza): self.xmpp.features.add('compression') log.debug('Stream Compressed!') compressed_socket = ZlibSocket(self.xmpp.socket) self.xmpp.set_socket(compressed_socket) raise RestartStream() def _handle_failure(self, stanza): pass xep_0138 = XEP_0138 register_plugin(XEP_0138)
def _remove_jid(self, iq, session): if iq['from'].bare not in self._admins: raise XMPPError('forbidden') form = self.xmpp['xep_0004'].stanza.Form() form['type'] = 'form' form['title'] = 'Remove XSF Member JID' form['instructions'] = 'Enter a JID for an XSF Member' form.add_field(var='jid', ftype='jid-single', title='JID', desc='XSF Member JID', required=True) session['payload'] = form session['has_next'] = False def handle_result(form, session): jid = JID(form['values']['jid']) if jid.bare in self._members: self._members.remove(jid) self._save_data() self.xmpp.event('xsf_jid_removed', jid) session['payload'] = None session['next'] = None return session session['next'] = handle_result return session register_plugin(XSFRoster)
""" Slixmpp: The Slick XMPP Library Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout This file is part of Slixmpp. See the file LICENSE for copying permission. """ from slixmpp.plugins import BasePlugin, register_plugin class XEP_0242(BasePlugin): name = 'xep_0242' description = 'XEP-0242: XMPP Client Compliance 2009' dependencies = set(['xep_0030', 'xep_0115', 'xep_0054', 'xep_0045', 'xep_0085', 'xep_0016', 'xep_0191']) register_plugin(XEP_0242)
""" Slixmpp: The Slick XMPP Library Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout This file is part of Slixmpp. See the file LICENSE for copying permission. """ from slixmpp.plugins import BasePlugin, register_plugin class XEP_0270(BasePlugin): name = 'xep_0270' description = 'XEP-0270: XMPP Compliance Suites 2010' dependencies = set([ 'xep_0030', 'xep_0115', 'xep_0054', 'xep_0163', 'xep_0045', 'xep_0085' ]) register_plugin(XEP_0270)
iq['from'] = ifrom iq.send() def getJoinedRooms(self): return self.rooms.keys() def getOurJidInRoom(self, roomJid): """ Return the jid we're using in a room. """ return "%s/%s" % (roomJid, self.ourNicks[roomJid]) def getJidProperty(self, room, nick, jidProperty): """ Get the property of a nick in a room, such as its 'jid' or 'affiliation' If not found, return None. """ if room in self.rooms and nick in self.rooms[room] and jidProperty in self.rooms[room][nick]: return self.rooms[room][nick][jidProperty] else: return None def getRoster(self, room): """ Get the list of nicks in a room. """ if room not in self.rooms.keys(): return None return self.rooms[room].keys() xep_0045 = XEP_0045 register_plugin(XEP_0045)
self._handle_compression, restart=True, order=self.config.get('order', 5)) def register_compression_method(self, name, handler): self.compression_methods[name] = handler def _handle_compression(self, features): for method in features['compression']['methods']: if method in self.compression_methods: log.info('Attempting to use %s compression' % method) c = Compress(self.xmpp) c['method'] = method c.send(now=True) return True return False def _handle_compressed(self, stanza): self.xmpp.features.add('compression') log.debug('Stream Compressed!') compressed_socket = ZlibSocket(self.xmpp.socket) self.xmpp.set_socket(compressed_socket) raise RestartStream() def _handle_failure(self, stanza): pass xep_0138 = XEP_0138 register_plugin(XEP_0138)
# Slixmpp: The Slick XMPP Library # Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout # This file is part of Slixmpp. # See the file LICENSE for copying permission. from slixmpp.plugins import BasePlugin, register_plugin class XEP_0106(BasePlugin): name = 'xep_0106' description = 'XEP-0106: JID Escaping' dependencies = {'xep_0030'} def session_bind(self, jid): self.xmpp['xep_0030'].add_feature(feature='jid\\20escaping') def plugin_end(self): self.xmpp['xep_0030'].del_feature(feature='jid\\20escaping') register_plugin(XEP_0106)
""" Slixmpp: The Slick XMPP Library Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout This file is part of Slixmpp. See the file LICENSE for copying permission. """ from slixmpp.plugins import BasePlugin, register_plugin class XEP_0302(BasePlugin): name = 'xep_0302' description = 'XEP-0302: XMPP Compliance Suites 2012' dependencies = { 'xep_0030', 'xep_0115', 'xep_0054', 'xep_0163', 'xep_0045', 'xep_0085', 'xep_0184', 'xep_0198' } register_plugin(XEP_0302)
if msg['type'] not in ('normal', 'chat'): return if not self.xmpp['xsf_roster'].is_member(user): log.warn('Unknown user: %s', user) return if user not in self.sessions: self.sessions[user] = VotingSession(self.xmpp, user) session = self.sessions[user] try: session.process(msg['body'], ) except StopIteration: pass register_plugin(XSFVotingChat) class VotingSession(object): def __init__(self, xmpp, user): self.xmpp = xmpp self.user = user self._session = self._process() next(self._session) def end(self): self.xmpp.client_roster[self.user]['name'] or self.user.bare self.send('end') del self.xmpp['xsf_voting_chat'].sessions[self.user] def process(self, user_resp):
'get-registered-users-list', 'get-disabled-users-list', 'get-online-users-list', 'get-online-users', 'get-active-users', 'get-idle-userslist', 'announce', 'set-motd', 'edit-motd', 'delete-motd', 'set-welcome', 'delete-welcome', 'edit-admin', 'restart', 'shutdown' } def get_commands(self, jid=None, **kwargs): if jid is None: jid = self.xmpp.boundjid.server return self.xmpp['xep_0050'].get_commands(jid, **kwargs) def create_command(name): def admin_command(self, jid=None, session=None, ifrom=None): if jid is None: jid = self.xmpp.boundjid.server self.xmpp['xep_0050'].start_command( jid=jid, node='http://jabber.org/protocol/admin#%s' % name, session=session, ifrom=ifrom) return admin_command for cmd in XEP_0133.commands: setattr(XEP_0133, cmd.replace('-', '_'), create_command(cmd)) register_plugin(XEP_0133)
return session def _handle_limited_voting(self, iq, session): voting_session = self.xmpp['xsf_voting'].start_voting(session['from']) section = session['ballot_section'] form = self.xmpp['xep_0004'].stanza.Form() form['type'] = 'form' form['title'] = 'XSF Election: %s' % section['title'] form[ 'instructions'] = 'Select the applicants you approve for %s.' % section[ 'title'] random.shuffle(section['items']) items = deque(section['items']) for i in range(0, int(section['limit'])): form.add_field(var='choice-%s' % i, ftype='list-single', label='Seat %s' % str(i + 1)) for item in items: form.field['choice-%s' % i].add_option(value=item['name']) items.rotate(1) session['payload'] = form session['next'] = self._handle_limited_voting return session register_plugin(XSFVotingAdhoc)