本文整理汇总了Python中wokkel.client.XMPPClient.send方法的典型用法代码示例。如果您正苦于以下问题:Python XMPPClient.send方法的具体用法?Python XMPPClient.send怎么用?Python XMPPClient.send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wokkel.client.XMPPClient
的用法示例。
在下文中一共展示了XMPPClient.send方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: XmppBackend
# 需要导入模块: from wokkel.client import XMPPClient [as 别名]
# 或者: from wokkel.client.XMPPClient import send [as 别名]
class XmppBackend(ProtocolBackend):
protocol_name = 'xmpp'
def configure(self, *args, **kwargs):
# user args
self.nick = kwargs.get('nick')
# TODO: remove, make this just the bot name...
self.room_nick = kwargs.get('room_nick')
if self.room_nick is None:
self.room_nick = self.nick
self.log_traffic = kwargs.get('log_traffic', False)
#TODO: remove localhost default, fail.
self.server = kwargs.get('server', 'localhost')
self.port = kwargs.get('port', XMPP_DEFAULT_PORT)
self.use_ssl = kwargs.get('use_ssl', True)
self.keepalive_freq = kwargs.get('keepalive_freq') # defaults to None
if type(self.keepalive_freq) not in (None, float):
try:
self.keepalive_freq = float(self.keepalive_freq)
except Exception as e:
self.log.error('invalid keepalive passed in, {0!r}: {1!r}'.format(self.keepalive_freq, e))
self.keepalive_freq = None
#TODO: have this default to botname @ .
self.jabber_id = kwargs.get('jabber_id', self.nick + '@' + self.server)
#self.room_jabber_id = # do we need this for servers that act wonky? maybe.
self.password = kwargs.get('password')
self.rooms = kwargs.get('rooms')
# allow users to define custom handlers? not now.
#self.subprotocol_handlers = kwargs.get()
# internal
self.bot_jid = jid.internJID(self.jabber_id)
# probably want to override client?
self.client = XMPPClient(self.bot_jid, self.password, host=self.server)
if self.log_traffic is True:
self.client.logTraffic = True
# def connect_handlers(self):
# for subprotocol in self.subprotocol_handlers:
# instance = subprotocol()
# instance.setHandlerParent(self.client)
def connect(self, *args, **kwargs):
#TODO: try moving this below
self.client.startService()
# setup handlers
self.muc_handler = MucBot(self.rooms, self.room_nick, backend=self)
self.muc_handler.setHandlerParent(self.client)
self.privatechat_handler = PrivateChatBot(backend=self)
self.privatechat_handler.setHandlerParent(self.client)
self.presence = xmppim.PresenceClientProtocol()
self.presence.setHandlerParent(self.client)
self.presence.available()
self.keepalive = ClientKeepalive(interval=self.keepalive_freq)
self.keepalive.setHandlerParent(self.client)
def handle_action(self, action):
self.log.debug('XMPP ACTION : {0!r}'.format(action))
if action.action_type != 'message':
return
body = str(action.meta.get('body'))
if not body:
return
if not action.destination_rooms:
return
for room in action.destination_rooms:
if action.scope == 'public':
room_jid = jid.internJID(room)
message = muc.GroupChat(recipient=room_jid, body=body)
self.client.send(message.toElement())
if action.scope == 'private':
if room is not None:
msg = xmppim.Message(recipient=jid.internJID(room),
sender=self.bot_jid,
body=body)
self.client.send(msg.toElement())