Created
October 2, 2018 11:25
-
-
Save s-nt-s/9cd013f4ede2799a412c0a82b28903ed to your computer and use it in GitHub Desktop.
Prueba de bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys | |
import logging | |
import getpass | |
from optparse import OptionParser | |
import time | |
import sleekxmpp | |
class EchoBot(sleekxmpp.ClientXMPP): | |
""" | |
copy from http://sleekxmpp.com/getting_started/echobot.html | |
""" | |
def __init__(self, jid, password): | |
sleekxmpp.ClientXMPP.__init__(self, jid, password) | |
self.add_event_handler("session_start", self.start) | |
self.add_event_handler("message", self.message) | |
def start(self, event): | |
self.send_presence() | |
self.get_roster() | |
def message(self, msg): | |
if msg['type'] in ('chat', 'normal'): | |
user = msg['from'] | |
rpl = msg.reply() | |
for i in range(0, 5): | |
text = "Reply %s to %s" % (i, user) | |
rpl['body']=text | |
rpl.send() | |
time.sleep(1) | |
if __name__ == '__main__': | |
# Setup the command line arguments. | |
optp = OptionParser() | |
# Output verbosity options. | |
optp.add_option('-q', '--quiet', help='set logging to ERROR', | |
action='store_const', dest='loglevel', | |
const=logging.ERROR, default=logging.INFO) | |
optp.add_option('-d', '--debug', help='set logging to DEBUG', | |
action='store_const', dest='loglevel', | |
const=logging.DEBUG, default=logging.INFO) | |
optp.add_option('-v', '--verbose', help='set logging to COMM', | |
action='store_const', dest='loglevel', | |
const=5, default=logging.INFO) | |
# JID and password options. | |
optp.add_option("-j", "--jid", dest="jid", | |
help="JID to use") | |
optp.add_option("-p", "--password", dest="password", | |
help="password to use") | |
opts, args = optp.parse_args() | |
# Setup logging. | |
logging.basicConfig(level=opts.loglevel, | |
format='%(levelname)-8s %(message)s') | |
if opts.jid is None: | |
opts.jid = raw_input("Username: ") | |
if opts.password is None: | |
opts.password = getpass.getpass("Password: ") | |
xmpp = EchoBot(opts.jid, opts.password) | |
xmpp.register_plugin('xep_0030') | |
xmpp.register_plugin('xep_0004') | |
xmpp.register_plugin('xep_0060') | |
xmpp.register_plugin('xep_0199') | |
xmpp.connect() | |
xmpp.process() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
El problema es que si escribo al mismo tiempo desde dos usuarios a este bot la respuesta es:
Es decir, hasta que no se ha respondido completamente al primer usuario no se contesta al segundo, cuando lo deseado es que los conteste en paralelo.