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 load_twitchchat(self, username, oauth, channel, client_id): logger.info("Loading twitchchat for {0} and channel {1}".format(username, channel)) self.twitchchat = twitch_chat(username, oauth, [channel], client_id)
# the time in seconds to wait since the last occurance of a given emote ellapse = 5 # How many emotes / ellapse are required for an alert to be sent (in percentage of current viewers of streamer) thresholdFactor = 0.0001 # Counter for emotes [0] is timestamp, [1] is count of emotes targetEmoteCounter = {'POG':[0,0], 'HA': [0,0], 'LUL': [0,0], '?': [0,0]} # Store clip URLs as they are generated clipStore = [] # Uncomment to see entire set-up process # logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG) tirc = twitch_chat('TheMenEgg', chatOauthToken, [channelName],clientID) # {"match_status": -1 } player not in match # {"match_status": 18237141 } player in match # Function called when new message in Twitch chat def new_message(msg): print(msg['message'] + " " + str(targetEmoteCounter) + " " + str(json.loads(requests.get("https://api.twitch.tv/kraken/streams/" + str(broadcasterID), data=None, headers={'Accept': 'application/vnd.twitchtv.v5+json', 'Client-ID': clientID}) .content.decode('latin1'))['stream']['viewers'] * thresholdFactor) ) playState[0] = fetchCurrentMatchId(summonerName, summonerRegion) if playState[0] == -1: playState[1] = time.time() tirc.stop() else: for targetEmote in targetEmoteCounter.keys():
shutil.rmtree('profile_images', ignore_errors=True) if args.testtwitch: from twitch.api import v3 as twitch featured_streams = twitch.streams.featured(limit=5)['featured'] for x in featured_streams: config['twitch_channels'].append(x['stream']['channel']['name']) try: console = TwitchChatDisplay(config['screen_width'], config['screen_height']) console.display_message("Loading twitch_api manager") thandler = twitchevents(config['twitch_channels']) thandler.subscribe_new_follow(console.new_followers) thandler.subscribe_viewers_change(console.new_viewers) console.display_message("Loading twitch_message handler") tirc = twitch_chat(config['twitch_username'], config['twitch_oauth'], config['twitch_channels'], config['client_id']) tirc.subscribeChatMessage(console.new_twitchmessage) tirc.subscribeNewSubscriber(console.new_subscriber) ytchat = None if 'youtube_enabled' in config: if config['youtube_enabled']: console.display_message("Grabbing youtube chat id") 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)
'--debug', help="Enable debugging statements", action="store_const", dest="loglevel", const=logging.DEBUG, default=logging.INFO,) args = parser.parse_args() logging.basicConfig(level=args.loglevel, format='%(asctime)s.%(msecs)d %(levelname)s %(name)s : %(message)s', datefmt='%H:%M:%S') config = get_config() if args.test: from twitch.api import v3 as twitch featured_streams = twitch.streams.featured(limit=5)['featured'] for x in featured_streams: config['twitch_channels'].append(x['stream']['channel']['name']) console = TwitchChatDisplay(1920, 1080) thandler = TwitchHandler(config['twitch_channels']) thandler.subscribe_new_follow(console.new_followers) tirc = twitch_chat(config['twitch_username'], config['twitch_oauth'], config['twitch_channels']) tirc.subscribeChatMessage(console.new_twitchmessage) tirc.subscribeNewSubscriber(console.new_subscriber) try: console.start() thandler.start() tirc.run() finally: console.stop() thandler.stop()
def load_twitchchat(self, username, oauth, channel): logger.info("Loading twitchchat for {0} and channel {1}".format(username, channel)) self.twitchchat = twitch_chat(username, oauth, [channel])