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)
#!/usr/bin/env python from time import sleep from youtubechat import YoutubeLiveChat, get_live_chat_id_for_stream_now livechat_id = get_live_chat_id_for_stream_now("oauth_creds") chat_obj = YoutubeLiveChat("oauth_creds", [livechat_id]) # msg in this case is a LiveChatMessage object defined in ytchat.py def respond(msgs, chatid): for msg in msgs: print(f"NEW MESSAGE: {msg.published_at} | {msg}") #print(msg) #msg.delete() #chat_obj.send_message("RESPONSE!", chatid) try: chat_obj.start() chat_obj.subscribe_chat_message(respond) chat_obj.join() finally: chat_obj.stop()
chatId = None if args.testyoutube: from youtubechat import get_top_stream_chat_ids chatId = get_top_stream_chat_ids("oauth_creds")[0] else: chatId = get_live_chat_id_for_stream_now('oauth_creds') console.display_message("Loading youtube chat handler") ytchat = YoutubeLiveChat('oauth_creds', [chatId]) ytchat.subscribe_chat_message(console.new_ytmessage) if 'ignored_users' in config: for user in config['ignored_users']: console.ignore_user(user) try: console.display_message("Loading complete, awaiting messages") console.start() thandler.start() tirc.start() if ytchat: ytchat.start() while True: time.sleep(0.1) if pygame.display.get_init(): pygame.event.pump() finally: console.stop() thandler.stop() if ytchat: ytchat.stop() finally: pygame.quit()
#!/usr/bin/env python from time import sleep from youtubechat import YoutubeLiveChat, get_live_chat_id_for_stream_now livechat_id = get_live_chat_id_for_stream_now("oauth_creds") chat_obj = YoutubeLiveChat("oauth_creds", [livechat_id]) def respond(msgs, chatid): for msg in msgs: print(msg) msg.delete() chat_obj.send_message("RESPONSE!", chatid) try: chat_obj.start() chat_obj.subscribe_chat_message(respond) chat_obj.join() finally: chat_obj.stop()