Пример #1
0
class Chatmirror(object):
    def __init__(self, config):
        self.config = config
        self.tirc = twitch_chat(config['twitch_username'],
                                config['twitch_oauth'],
                                [config['twitch_channel']],
                                config['client_id'])
        self.tirc.subscribeChatMessage(self.new_twitchmessage)
        self.chatId = get_live_chat_id_for_stream_now('oauth_creds')
        self.ytchat = YoutubeLiveChat('oauth_creds', [self.chatId])
        self.ytchat.subscribe_chat_message(self.new_ytmessage)

    def start(self):
        self.ytchat.start()
        self.tirc.start()

    def join(self):
        self.tirc.join()

    def stop(self):
        self.tirc.stop()
        self.ytchat.stop()

    def new_ytmessage(self, msgs, chat_id):
        for msg in msgs:
            to_send = u"{0} : {1}".format(msg.author.display_name,
                                          msg.message_text)
            logger.debug(to_send)
            self.tirc.send_message(config['twitch_channel'], to_send)

    def new_twitchmessage(self, msg):
        uname = msg['display-name'] or msg['username']
        to_send = "{0} : {1}".format(uname, msg['message'])
        logger.debug(to_send)
        self.ytchat.send_message(to_send, self.chatId)