예제 #1
0
파일: misc.py 프로젝트: korvys/lrrbot
def viewers(lrrbot, conn, event, respond_to):
    """
	Command: !viewers

	Post the number of viewers currently watching the stream
	"""
    stream_info = twitch.get_info()
    if stream_info:
        viewers = stream_info.get("viewers")
    else:
        viewers = None

    # Since we're using TWITCHCLIENT 3, we don't get join/part messages, so we can't just use
    # len(lrrbot.channels["#loadingreadyrun"].userdict)
    # as that dict won't be populated. Need to call this api instead.
    chatters = utils.http_request(
        "http://tmi.twitch.tv/group/user/%s/chatters" % config["channel"])
    chatters = json.loads(chatters).get("chatter_count")

    if viewers is not None:
        viewers = "%d %s viewing the stream." % (viewers, "user"
                                                 if viewers == 1 else "users")
    else:
        viewers = "Stream is not live."
    if chatters is not None:
        chatters = "%d %s in the chat." % (chatters, "user"
                                           if chatters == 1 else "users")
    else:
        chatters = "No-one in the chat."
    conn.privmsg(respond_to, "%s %s" % (viewers, chatters))
예제 #2
0
	def on_notification(self, conn, event, respond_to):
		"""Handle notification messages from Twitch, sending the message up to the web"""
		log.info("Notification: %s" % event.arguments[0])
		notifyparams = {
			'apipass': config['apipass'],
			'message': event.arguments[0],
			'eventtime': time.time(),
		}
		if irc.client.is_channel(event.target):
			notifyparams['channel'] = event.target[1:]
		subscribe_match = self.re_subscription.match(event.arguments[0])
		if subscribe_match:
			notifyparams['subuser'] = subscribe_match.group(1)
			try:
				channel_info = twitch.get_info(subscribe_match.group(1))
			except:
				pass
			else:
				if channel_info.get('logo'):
					notifyparams['avatar'] = channel_info['logo']
			# have to get this in a roundabout way as datetime.date.today doesn't take a timezone argument
			today = datetime.datetime.now(config['timezone']).date().toordinal()
			if today != storage.data.get("storm",{}).get("date"):
				storage.data["storm"] = {
					"date": today,
					"count": 0,
				}
			storage.data["storm"]["count"] += 1
			storage.save()
			conn.privmsg(respond_to, "lrrSPOT Thanks for subscribing, %s! (Today's storm count: %d)" % (notifyparams['subuser'], storage.data["storm"]["count"]))

			self.subs.add(subscribe_match.group(1).lower())
			storage.data['subs'] = list(self.subs)
			storage.save()
		utils.api_request('notifications/newmessage', notifyparams, 'POST')
예제 #3
0
파일: misc.py 프로젝트: korvys/lrrbot
def viewers(lrrbot, conn, event, respond_to):
	"""
	Command: !viewers

	Post the number of viewers currently watching the stream
	"""
	stream_info = twitch.get_info()
	if stream_info:
		viewers = stream_info.get("viewers")
	else:
		viewers = None
	
	# Since we're using TWITCHCLIENT 3, we don't get join/part messages, so we can't just use
	# len(lrrbot.channels["#loadingreadyrun"].userdict)
	# as that dict won't be populated. Need to call this api instead.
	chatters = utils.http_request("http://tmi.twitch.tv/group/user/%s/chatters" % config["channel"])
	chatters = json.loads(chatters).get("chatter_count")

	if viewers is not None:
		viewers = "%d %s viewing the stream." % (viewers, "user" if viewers == 1 else "users")
	else:
		viewers = "Stream is not live."
	if chatters is not None:
		chatters = "%d %s in the chat." % (chatters, "user" if chatters == 1 else "users")
	else:
		chatters = "No-one in the chat."
	conn.privmsg(respond_to, "%s %s" % (viewers, chatters))
예제 #4
0
def get_uptime():
    # Get uptime and generate link to VOD
    current_time = datetime.utcnow()
    channel_data = get_info()
    start_time = channel_data['stream_created_at']
    # u'2016-11-23T13:15:46Z'
    start_time = datetime.strptime(start_time, "%Y-%m-%dT%H:%M:%SZ")
    
    difference = current_time - start_time
    minutes, seconds = divmod(difference.seconds, 60)
    hours, minutes = divmod(minutes, 60)
    return {'hours':int(hours), 'minutes':int(minutes), 'seconds':int(seconds)}
예제 #5
0
def highlight():
    channel_data = get_info()
    uptime = get_uptime()
    uptime['seconds']
    #Remove 46 seconds from Highlight
    if uptime['seconds'] > 46:
        uptime['minutes'] -= 1
        uptime['seconds'] += 14
    else:
        uptime['seconds'] -= 46       
    VOD_link = get_current_video_id(channel = channel_data['display_name'])
    #https://www.twitch.tv/loadingreadyrun/v/98781251?t=1h3m15s
    highlight = VOD_link + '?t=%ih%im%is' %(uptime['hours'], uptime['minutes'], uptime['seconds'])
    return highlight
예제 #6
0
파일: misc.py 프로젝트: MatthewCox/lrrbot
def uptime(lrrbot, conn, event, respond_to):
	"""
	Command: !uptime

	Post the duration the stream has been live.
	"""

	stream_info = twitch.get_info()
	if stream_info and stream_info.get("stream_created_at"):
		start = dateutil.parser.parse(stream_info["stream_created_at"])
		now = datetime.datetime.now(datetime.timezone.utc)
		conn.privmsg(respond_to, "The stream has been live for %s" % utils.nice_duration(now-start, 0))
	elif stream_info:
		conn.privmsg(respond_to, "Twitch won't tell me when the stream went live.")
	else:
		conn.privmsg(respond_to, "The stream is not live.")
예제 #7
0
def highlight(lrrbot, conn, event, respond_to, description):
	"""
	Command: !highlight DESCRIPTION

	For use when something particularly awesome happens onstream, adds an entry on the Highlight Reel spreadsheet: https://docs.google.com/spreadsheets/d/1yrf6d7dPyTiWksFkhISqEc-JR71dxZMkUoYrX4BR40Y

	Note that the highlights won't appear on the spreadsheet immediately, as the link won't be available until the stream finishes and the video is in the archive. It should appear within a day.
	"""
	if not twitch.get_info()["live"]:
		conn.privmsg(respond_to, "Not currently streaming.")
		return
	storage.data.setdefault("staged_highlights", [])
	storage.data["staged_highlights"] += [{
		"time": time.time(),
		"user": irc.client.NickMask(event.source).nick,
		"description": description,
	}]
	storage.save()
	conn.privmsg(respond_to, "Highlight added.")