xep_0133.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """
  2. SleekXMPP: The Sleek XMPP Library
  3. Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
  4. This file is part of SleekXMPP.
  5. See the file LICENSE for copying permission.
  6. """
  7. from sleekxmpp.plugins import BasePlugin, register_plugin
  8. class XEP_0133(BasePlugin):
  9. name = 'xep_0133'
  10. description = 'XEP-0133: Service Administration'
  11. dependencies = set(['xep_0030', 'xep_0004', 'xep_0050'])
  12. commands = set(['add-user', 'delete-user', 'disable-user',
  13. 'reenable-user', 'end-user-session', 'get-user-password',
  14. 'change-user-password', 'get-user-roster',
  15. 'get-user-lastlogin', 'user-stats', 'edit-blacklist',
  16. 'edit-whitelist', 'get-registered-users-num',
  17. 'get-disabled-users-num', 'get-online-users-num',
  18. 'get-active-users-num', 'get-idle-users-num',
  19. 'get-registered-users-list', 'get-disabled-users-list',
  20. 'get-online-users-list', 'get-online-users',
  21. 'get-active-users', 'get-idle-userslist', 'announce',
  22. 'set-motd', 'edit-motd', 'delete-motd', 'set-welcome',
  23. 'delete-welcome', 'edit-admin', 'restart', 'shutdown'])
  24. def get_commands(self, jid=None, **kwargs):
  25. if jid is None:
  26. jid = self.xmpp.boundjid.server
  27. return self.xmpp['xep_0050'].get_commands(jid, **kwargs)
  28. def create_command(name):
  29. def admin_command(self, jid=None, session=None, ifrom=None, block=False):
  30. if jid is None:
  31. jid = self.xmpp.boundjid.server
  32. self.xmpp['xep_0050'].start_command(
  33. jid=jid,
  34. node='http://jabber.org/protocol/admin#%s' % name,
  35. session=session,
  36. ifrom=ifrom,
  37. block=block)
  38. return admin_command
  39. for cmd in XEP_0133.commands:
  40. setattr(XEP_0133, cmd.replace('-', '_'), create_command(cmd))
  41. register_plugin(XEP_0133)