def __init__(self, username, password, res=None, debug=False, privatedomain=False, acceptownmsgs=False, handlers=None): """Initializes the jabber bot and sets up commands. username and password should be clear ;) If res provided, res will be ressourcename, otherwise it defaults to classname of childclass If debug is True log messages of xmpppy will be printed to console. Logging of Jabberbot itself is NOT affected. If privatedomain is provided, it should be either True to only allow subscriptions from the same domain as the bot or a string that describes the domain for which subscriptions are accepted (e.g. 'jabber.org'). If acceptownmsgs it set to True, this bot will accept messages from the same JID that the bot itself has. This is useful when using JabberBot with a single Jabber account and multiple instances that want to talk to each other. If handlers are provided, default handlers won't be enabled. Usage like: [('stanzatype1', function1), ('stanzatype2', function2)] Signature of function should be callback_xx(self, conn, stanza), where conn is the connection and stanza the current stanza in process. First handler in list will be served first. Don't forget to raise exception xmpp.NodeProcessed to stop processing in other handlers (see callback_presence) """ super(JabberBot, self).__init__() self.__debug = debug self.log = logging.getLogger(__name__) self.__username = username self.__password = password self.jid = JID(self.__username) self.res = (res or self.__class__.__name__) self.conn = None self.__finished = False self.__show = None self.__status = None self.__seen = {} self.__lastping = time.time() self.__privatedomain = privatedomain self.__acceptownmsgs = acceptownmsgs self.handlers = (handlers or [('message', self.callback_message), ('presence', self.callback_presence)]) # Collect commands from source self.roster = None
def auto_reply(event, message): stream.send_presence() from_jid = JID(message.attr['from']) if message.is_composing(): logging.warning("%s is composing", from_jid.nick) if message.is_active(): logging.warning("%s is active", from_jid.nick) body = message.get_body() if body: logging.critical("%s says: %s", from_jid.nick, body) stream.send_message(body, to=from_jid.text) stream.send_presence(to=from_jid.text)
#!/usr/bin/python # -*- coding: utf-8 -*- CONFIG_FILE = "config.cfg" """DO NOT EDIT THE NEXT LINES!!!!!!""" from xmpp import JID # sample config, you must edit CONFIG_FILE file CONFIG = { 'jid': '[email protected]/Jabber Feed Notifier', 'pass': '******', 'server': 'server.com', 'port': 5223, 'durus_file': 'data/feeds.durus', 'admins': [] # admin jids } # load configuration pf = open(CONFIG_FILE, 'r') CONFIG.update(eval(pf.read())) pf.close() CONFIG['jid'] = JID(CONFIG['jid'])
import time import logging import traceback import coloredlogs from xmpp import XMLStream from xmpp import XMPPConnection from xmpp import JID from xmpp import sasl from xmpp.auth import SASLAuthenticationHandler DEBUG = True DOMAIN = 'falcao.it' PORT = 5222 jid = JID('[email protected]/xmpp-test') password = '******' SASL_MECHANISM = 'SCRAM-SHA-1' SASL_HANDLER = sasl.client_authenticator_factory(SASL_MECHANISM) def application(): # Setting up logs coloredlogs.install(level=DEBUG and logging.DEBUG or logging.INFO) # create a non-blocking XMPP-connection connection = XMPPConnection(DOMAIN, PORT, debug=DEBUG) # create a XML stream stream = XMLStream(connection, debug=DEBUG)
import time import logging import traceback import coloredlogs from xmpp import XMLStream from xmpp import XMPPConnection from xmpp import JID from xmpp import sasl from xmpp.auth import SASLAuthenticationHandler DEBUG = True DOMAIN = 'falcao.it' jid = JID('[email protected]/xmpp-test') password = '******' SASL_MECHANISM = 'SCRAM-SHA-1' SASL_HANDLER = sasl.client_authenticator_factory(SASL_MECHANISM) def application(): # Setting up logs coloredlogs.install(level=DEBUG and logging.DEBUG or logging.INFO) # create a non-blocking XMPP-connection connection = XMPPConnection(DOMAIN, 5222, debug=DEBUG) # create a XML stream stream = XMLStream(connection, debug=DEBUG)