1
回答
总结最近学习的如何编写gtalk机器人
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

只能说开放的协议给我们了太多可能,

加phzggzs@gmail.com发送 -qsbk 可获取最新的糗事百科

闲话少说:

使用python库

git clone https://github.com/fritzy/SleekXMPP.git

简单的代码 

class SendMsgBot(sleekxmpp.ClientXMPP):

    """
    A basic SleekXMPP bot that will log in, send a message,
    and then log out.
    """

    def __init__(self, jid, password,):
        sleekxmpp.ClientXMPP.__init__(self, jid, password)
        self.recipient = recipient
        self.add_event_handler("session_start", self.start)
        #触发接受的消息
        self.add_event_handler("message", self.sig_message)

    def start(self, event):
        self.send_presence()
        self.get_roster()

    def sig_message(self, msg):
        ''' 处理命令 '''
        message = ''
        ''' 发送回复 '''
        self.send_message(mto=self.recipient,
                          mbody=message,
                          mtype='chat')
xmpp = SendMsgBot("gtalk", "passwd")
xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0199') # XMPP Ping
if xmpp.connect():
    xmpp.process(threaded=True)

举报
顶部