Anton Shestakov <av6@dwimlabs.net>, Mon, 09 May 2016 21:51:10 +0800
rollbot: add --quiet in addition to --debug
rollbot.py
Permissions: -rw-r--r--
from argparse import ArgumentParser if sys.version_info < (3, 0): sys.setdefaultencoding('utf8') class RollBot(sleekxmpp.ClientXMPP): def __init__(self, jid, password, nick): sleekxmpp.ClientXMPP.__init__(self, jid, password) self.add_event_handler('session_start', self.start) self.add_event_handler('groupchat_invite', self.muc_invite) self.add_event_handler('groupchat_direct_invite', self.muc_direct_invite) def muc_invite(self, invite): password = '' # https://github.com/fritzy/SleekXMPP/issues/409 self.plugin['xep_0045'].joinMUC(room, self.nick, password=password, wait=True) def muc_direct_invite(self, invite): room = invite['groupchat_invite']['jid'] password = invite['groupchat_invite']['password'] self.plugin['xep_0045'].joinMUC(room, self.nick, password=password, wait=True) parser = ArgumentParser() parser.add_argument('-j', '--jid', dest='jid', help='JID to use') parser.add_argument('-p', '--password', dest='password', help='password to use') parser.add_argument('-n', '--nick', dest='nick', help='MUC nickname', default='rollbot') group = parser.add_mutually_exclusive_group() group.add_argument('-q', '--quiet', help='set logging to ERROR', action='store_const', dest='loglevel', const=logging.ERROR, default=logging.INFO) group.add_argument('-d', '--debug', help='set logging to DEBUG', action='store_const', dest='loglevel', const=logging.DEBUG, default=logging.INFO) args = parser.parse_args() logging.basicConfig(level=args.loglevel, format='%(asctime)s %(levelname)-8s %(message)s') rollbot = RollBot(args.jid, args.password, args.nick) rollbot.auto_authorize = True rollbot.auto_subscribe = True rollbot.register_plugin('xep_0030') # Service Discovery rollbot.register_plugin('xep_0045') # Multi-User Chat rollbot.register_plugin('xep_0092') # Software Version rollbot.register_plugin('xep_0199') # XMPP Ping rollbot.register_plugin('xep_0202') # Entity Time rollbot.register_plugin('xep_0249') # Direct MUC Invitations logging.info('RollBot connected') rollbot.process(block=True) logging.info('RollBot disconnected') logging.fatal("RollBot couldn't connect") if __name__ == '__main__':