Ejemplo n.º 1
0
async def _run(
    messaging,
    live_chat_messages,
    live_chat_id,
):
    command_manager = AdapterCommandManager(messaging)
    frame = None
    while True:
        try:
            frame = messaging.sub_socket.recv_multipart(zmq.NOBLOCK)
        except zmq.error.ZMQError:
            pass
        if frame:
            message = decode_vex_message(frame)
            if message.type == 'CMD':
                command_manager.parse_commands(message)
            elif message.type == 'RSP':
                message = message.contents.get('response')
                body = {
                    'snippet': {
                        'type': 'textmessageEvent',
                        'liveChatId': live_chat_id,
                        'textMessageDetails': {
                            'messageText': message
                        }
                    }
                }

                live_chat_messages.insert(part='snippet', body=body).execute()

            frame = None

        await asyncio.sleep(1)
Ejemplo n.º 2
0
    def __init__(self, streamer_name, namespace, website_url, publish_address,
                 subscribe_address, service_name):

        self.log = logging.getLogger(__name__)
        self.log.setLevel(0)
        if not _WEBSOCKET_INSTALLED:
            self.log.error('Must install `websocket`')
        if not _REQUESTS_INSTALLED:
            self.log.error('Must install `requests')

        self.messaging = ZmqMessaging(service_name, publish_address,
                                      subscribe_address, service_name)

        self.messaging.start_messaging()
        self._streamer_name = streamer_name
        self.namespace = namespace
        self._website_url = website_url
        self.log.info('Getting Socket IO key!')
        self.key, heartbeat = self._connect_to_server_helper()
        self.log.info('Socket IO key got!')
        self.command_manager = AdapterCommandManager(self.messaging)
        self._thread = Thread(target=self.handle_subscription)
        self._thread.daemon = True
        self._thread.start()

        # alters URL to be more websocket...ie
        self._website_socket = self._website_url.replace('http', 'ws')
        self._website_socket += 'websocket/'
        self.nick = None
        super().__init__(self._website_socket + self.key,
                         on_open=self.on_open,
                         on_close=self.on_close,
                         on_message=self.on_message,
                         on_error=self.on_error)
Ejemplo n.º 3
0
def main(nick,
         password,
         host,
         channel,
         publish_address,
         subscribe_address,
         service_name):

    if not _IRC3_INSTALLED:
        logging.error('irc requires `irc3` to be installed. Please install '
                      'using `pip install irc3`')

    irc_client = create_irc_bot(nick,
                                password,
                                host,
                                channel=channel)

    try:
        messaging = ZmqMessaging(service_name,
                                 publish_address,
                                 subscribe_address,
                                 socket_filter=service_name)

        messaging.start_messaging()
    except ZMQError:
        return
    # Duck type messaging onto irc_client, FTW
    irc_client.messaging = messaging
    command_parser = AdapterCommandManager(messaging)
    irc_client.command_parser = command_parser

    """
    command_parser.register_command('server config', _default)
    command_parser.register_command('ip', _default)
    command_parser.register_command('join', _default)
    command_parser.register_command('kick', _default)
    command_parser.register_command('part', _default)
    command_parser.register_command('invite', _default)
    command_parser.register_command('topic', _default)
    command_parser.register_command('away', _default)
    """

    irc_client.create_connection()
    irc_client.add_signal_handlers()
    event_loop = asyncio.get_event_loop()
    asyncio.ensure_future(_check_subscription(irc_client))
    atexit.register(_send_disconnected(messaging))

    handle_close = _handle_close(messaging, event_loop)
    signal.signal(signal.SIGINT, handle_close)
    signal.signal(signal.SIGTERM, handle_close)
    try:
        event_loop.run_forever()
    except KeyboardInterrupt:
        pass
    event_loop.close()
    sys.exit()
Ejemplo n.º 4
0
    def __init__(self,
                 jid,
                 password,
                 room,
                 publish_address,
                 subscribe_address,
                 service_name,
                 bot_nick='EchoBot',
                 **kwargs):

        # Initialize the parent class
        if not _SLEEKXMPP_INSTALLED:
            logging.error('must install sleekxmpp')

        super().__init__(jid, password)
        self.messaging = ZmqMessaging(service_name,
                                      publish_address,
                                      subscribe_address,
                                      service_name)

        self.messaging.start_messaging()
        self.command_manager = AdapterCommandManager(self.messaging)

        self.room = room
        self.nick = bot_nick
        self.log = logging.getLogger(__file__)

        # One-shot helper method used to register all the plugins
        self._register_plugin_helper()

        self.add_event_handler("session_start", self.start)
        self.add_event_handler("groupchat_message", self.muc_message)
        self.add_event_handler('connected', self._connected)
        self.add_event_handler('disconnected', self._disconnected)
        self._thread = Thread(target=self.run)
        self._thread.daemon = True
        self._thread.start()
Ejemplo n.º 5
0
 def setUp(self):
     self.command_manager = AdapterCommandManager(Message())