self.channel.start_consuming()
def die(self):
+ logger.debug("Quitting...")
self.channel.stop_consuming()
+ logger.debug("action_worker gone")
def find_scheduled_action_by_mutex(self, mutex):
action_item = None
if item:
self.event_list.cancel(item)
- def run_action(self, action):
+ def run_action(self, action: Action):
logger.debug("Executing action %s", action)
# to prevent really stupid clients not scrolling at incoming messages very quickly.
"to": action.recipient,
"body": ' '.join(action.command.split('.')[1:]),
})
- process_message(routing_key=action.command, body=replay_body)
+ process_message(routing_key=action.command.encode("UTF-8"), body=replay_body)
if action.msg: # and rate_limit(RATE_CHAT | plugin.ratelimit_class):
time.sleep(delay)
import shlex
import pika
-import sleekxmpp
+import slixmpp
from distbot.bot import action_worker
from distbot.common.config import conf_get
logger = logging.getLogger(__name__)
logging.getLogger("pika").setLevel(logging.WARN)
-logging.getLogger('sleekxmpp').setLevel(logging.INFO)
+logging.getLogger('slixmpp').setLevel(logging.DEBUG)
+logging.getLogger('slixmpp.xmlstream.xmlstream').setLevel(logging.DEBUG)
-class Bot(sleekxmpp.ClientXMPP):
+class Bot(slixmpp.ClientXMPP):
def __init__(self, jid, password, rooms, nick):
super(Bot, self).__init__(jid, password)
self.rooms = rooms
self.nick = nick
+ # from slixmpp.plugins.xep_0045 import XEP_0045
+ # self.add_event_handler('handle_groupchat_presence', XEP_0045.handle_groupchat_presence)
self.add_event_handler('session_start', self.session_start)
self.add_event_handler('groupchat_message', self.muc_message)
self.add_event_handler('message', self.message_handler)
self.add_event_handler('muc::%s::got_online' % room, self.muc_online)
self._initialize_plugins()
- import ssl
- self.ssl_version = ssl.PROTOCOL_TLSv1_2
+ # import ssl
+ # self.ssl_version = ssl.PROTOCOL_TLSv1_2
def _initialize_plugins(self):
self.register_plugin('xep_0045')
logger.info("Stopping all workers...")
self.kill_workers()
logger.info("Stopping self...")
- super(Bot, self)._disconnect(reconnect, wait=False, send_close=True)
+ super(Bot, self).disconnect(reconnect)
logger.info("Gudbai...")
raise SystemExit()
self.send_presence(ppriority=0, pstatus=None, pshow=None)
for room in self.rooms:
logger.info('%s: joining' % room)
- ret = self.plugin['xep_0045'].joinMUC(
- room,
- self.nick,
- wait=True
- )
+ ret = self.plugin['xep_0045'].join_muc(room, self.nick, wait=True)
logger.info('%s: joined with code %s' % (room, ret))
self.initialize_actionthreads()
# self.message(msg)
def muc_online(self, msg):
- sender = get_nick_from_message(msg)
- if sender == self.nick:
- return
- process_message(
- 'userjoin.{}'.format(msg["from"]),
- body=json.dumps({
- "from": msg["from"].jid,
- "to": msg["to"].jid,
- "body": msg["body"].strip()
- })
- )
+ try:
+ sender = get_nick_from_message(msg)
+ if sender == self.nick:
+ return
+ process_message(
+ 'userjoin.{}'.format(msg["from"]),
+ body=json.dumps({
+ "from": msg["from"].jid,
+ "to": msg["to"].jid,
+ "body": msg["body"].strip()
+ })
+ )
+ except ValueError as e:
+ logger.exception(e)
@staticmethod
def get_amqp_routing_key(nick, msg):
bot = Bot(jid=conf_get("jid"), password=conf_get("password"), rooms=conf_get("rooms"),
nick=conf_get("bot_nickname"))
bot.connect()
- bot.process()
+ try:
+ bot.process()
+ except KeyboardInterrupt:
+ bot.disconnect()
+ finally:
+ bot.abort()
if __name__ == '__main__':