def auto_accept_invite(self, message): room = message['from'] muc = self.plugin['xep_0045'] muc.joinMUC(room, nick=NICK_NAME, wait=True) self.rooms.append(str(room)) logger.debug('Rooms: {}'.format(self.rooms)) with open('./rooms.json', 'w') as fp: json.dump(self.rooms, fp)
def zmq_handler(self): while True: # xmppmsg = self.Message() message = socket.recv_json() # message = json.loads(message[0]) if message['html']: logger.debug('hipchat receive html message {}'.format(message)) # content = xhtml2hipchat(message['html']) room = self.get_room_by_jid(message['id']) content = message['content'] room.notification(content, color='random', notify=True, format='html') else: logger.debug('hipchat receive message {}'.format(message)) self.send_message(mto=message['id'], mbody=message['content'], mtype=message['type'])
#! /usr/bin/env python # coding: utf-8 # LICENSE: # Date: # Author: konglx # File: # Description: __author__ = 'Konglx' from hypchat import HypChat from tombot.common.log import logger TOKEN = 'DZttvKCWeU4GpXxoqwJc4IG8bH636MjaCmLNZqc8' hc = HypChat(TOKEN) logger.debug('Hipchat rooms: {0}'.format(hc.rooms())) logger.debug('Hipchat users: {0}'.format(hc.users()))
retarded_hipchat_html_plain = REMOVE_EOL.sub('', xhtml) # Ignore formatting retarded_hipchat_html_plain = HIPCHAT_EOLS.sub('<br/>', retarded_hipchat_html_plain) # readd the \n where they probably fit best retarded_hipchat_html_plain = HIPCHAT_BOLS.sub('', retarded_hipchat_html_plain) # zap every tag left retarded_hipchat_html_plain = HIPCHAT_FORCE_PRE.sub('<body><pre>', retarded_hipchat_html_plain) # fixor pre retarded_hipchat_html_plain = HIPCHAT_FORCE_SLASH_PRE.sub('</pre></body>', retarded_hipchat_html_plain) # fixor /pre return retarded_hipchat_html_plain context = zmq.Context(1) socket = context.socket(zmq.DEALER) socket.setsockopt(zmq.IDENTITY, 'HipChat') _home = os.getenv('TOMBOT_HOME') req_socket = yaml.load(file('./hipchat.yaml'))['req_socket'] logger.debug(req_socket) socket.connect(req_socket) class HipChat(ClientXMPP): def __init__(self, jid, password): super(HipChat, self).__init__(jid, password) self.register_plugin('xep_0030') # Service Discovery self.register_plugin('xep_0045') # Multi-User Chat self.register_plugin('xep_0004') # Multi-User Chat backward compability (necessary for join room) self.register_plugin('xep_0199') # XMPP Ping self.register_plugin('xep_0203') # XMPP Delayed messages self.register_plugin('xep_0249') # XMPP direct MUC invites self.register_plugin('xep_0060') # PubSub # self.register_plugin('xep_0071')