示例#1
0
def viewers(lrrbot, conn, event, respond_to):
    """
	Command: !viewers
	Section: info

	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

    chatters = len(lrrbot.channels["#%s" % config["channel"]].users())
    # Twitch stops sending JOINs and PARTs at 1000 users. Need to double-check if over.
    if chatters > 950:
        data = yield from common.http.request_coro(
            "https://tmi.twitch.tv/group/user/%s/chatters" % config["channel"])
        chatters = json.loads(data).get("chatter_count", chatters)

    if viewers is not None:
        viewers = "%d %s viewing the stream." % (viewers, "user"
                                                 if viewers == 1 else "users")
    else:
        viewers = "Stream is not live."
    chatters = "%d %s in the chat." % (chatters,
                                       "user" if chatters == 1 else "users")
    conn.privmsg(respond_to, "%s %s" % (viewers, chatters))
示例#2
0
def highlight(lrrbot, conn, event, respond_to, description):
	"""
	Command: !highlight DESCRIPTION
	Section: misc

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

	stream_info = twitch.get_info()
	if not stream_info["live"]:
		conn.privmsg(respond_to, "Not currently streaming.")
		return
	now = datetime.datetime.now(datetime.timezone.utc)

	for video in (yield from twitch.get_videos(broadcasts=True)):
		uptime = now - dateutil.parser.parse(video["recorded_at"])
		if video["status"] == "recording":
			break
	else:
		with lrrbot.engine.begin() as pg_conn:
			pg_conn.execute(lrrbot.metadata.tables["highlights"].insert(),
				title=stream_info["status"], description=description, time=now, user=event.tags["user-id"])
		conn.privmsg(respond_to, "Highlight added.")
		return

	yield from gdata.add_rows_to_spreadsheet(SPREADSHEET, [
		format_row(stream_info["status"], description, video["url"], uptime, irc.client.NickMask(event.source).nick)
	])

	conn.privmsg(respond_to, "Highlight added.")
示例#3
0
def highlight(lrrbot, conn, event, respond_to, description):
    """
	Command: !highlight DESCRIPTION
	Section: misc

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

    stream_info = twitch.get_info()
    if not stream_info["live"]:
        conn.privmsg(respond_to, "Not currently streaming.")
        return
    now = datetime.datetime.now(datetime.timezone.utc)

    for video in (yield from twitch.get_videos(broadcasts=True)):
        uptime = now - dateutil.parser.parse(video["recorded_at"])
        if video["status"] == "recording":
            break
    else:
        with lrrbot.engine.begin() as pg_conn:
            pg_conn.execute(lrrbot.metadata.tables["highlights"].insert(),
                            title=stream_info["status"],
                            description=description,
                            time=now,
                            user_id=event.tags["user-id"])
        conn.privmsg(respond_to, "Highlight added.")
        return

    yield from gdata.add_rows_to_spreadsheet(SPREADSHEET, [
        format_row(stream_info["status"], description, video, uptime,
                   irc.client.NickMask(event.source).nick)
    ])

    conn.privmsg(respond_to, "Highlight added.")
示例#4
0
文件: misc.py 项目: andreasots/lrrbot
async def viewers(lrrbot, conn, event, respond_to):
	"""
	Command: !viewers
	Section: info

	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

	chatters = len(lrrbot.channels["#%s" % config["channel"]].users())
	# Twitch stops sending JOINs and PARTs at 1000 users. Need to double-check if over.
	if chatters > 950:
		data = await common.http.request_coro("https://tmi.twitch.tv/group/user/%s/chatters" % config["channel"])
		chatters = json.loads(data).get("chatter_count", chatters)

	if viewers is not None:
		viewers = "%d %s viewing the stream." % (viewers, "user" if viewers == 1 else "users")
	else:
		viewers = "Stream is not live."
	chatters = "%d %s in the chat." % (chatters, "user" if chatters == 1 else "users")
	conn.privmsg(respond_to, "%s %s" % (viewers, chatters))
示例#5
0
def uptime_msg(stream_info=None, factor=1):
	if stream_info is None:
		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)
		return "The stream has been live for %s." % common.time.nice_duration((now - start) * factor, 0)
	elif stream_info and stream_info.get('live'):
		return "Twitch won't tell me when the stream went live."
	else:
		return "The stream is not live."
示例#6
0
文件: misc.py 项目: andreasots/lrrbot
def uptime_msg(stream_info=None, factor=1):
	if stream_info is None:
		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)
		return "The stream has been live for %s." % common.time.nice_duration((now - start) * factor, 0)
	elif stream_info and stream_info.get('live'):
		return "Twitch won't tell me when the stream went live."
	else:
		return "The stream is not live."
示例#7
0
    async def check_stream(self):
        log.debug("Checking stream")
        data = twitch.get_info(use_fallback=False)
        is_live = bool(data and data['live'])

        if is_live and not self.was_live:
            log.debug("Stream is now live")
            self.was_live = True
            await rpc.eventserver.event('stream-up', {}, None)
            await rpc.eris.announcements.stream_up(data)
        elif not is_live and self.was_live:
            log.debug("Stream is now offline")
            self.was_live = False
            await rpc.eventserver.event('stream-down', {}, None)

        self.schedule()
示例#8
0
	async def check_stream(self):
		log.debug("Checking stream")
		data = twitch.get_info(use_fallback=False)
		is_live = bool(data and data['live'])

		if is_live and not self.was_live:
			log.debug("Stream is now live")
			self.was_live = True
			await rpc.eventserver.event('stream-up', {}, None)
			await rpc.eris.announcements.stream_up(data)
		elif not is_live and self.was_live:
			log.debug("Stream is now offline")
			self.was_live = False
			await rpc.eventserver.event('stream-down', {}, None)

		self.schedule()
示例#9
0
def main():
	if twitch.get_info()["live"]:
		print("Stream is live.")
		return

	highlights = get_staged_highlights()
	videos = []
	for highlight in highlights:
		highlight["video"] = yield from lookup_video(highlight, videos)

	yield from gdata.add_rows_to_spreadsheet(SPREADSHEET, [
		format_row(highlight["title"], highlight["description"], highlight["video"]["url"],
			 highlight["time"] - highlight["video"]["recorded_at"], highlight["nick"])
		for highlight in highlights
	])
	delete_staged_highlights(highlights)
示例#10
0
def main():
	if twitch.get_info()["live"]:
		print("Stream is live.")
		return

	highlights = get_staged_highlights()
	videos = []
	for highlight in highlights:
		highlight["video"] = yield from lookup_video(highlight, videos)

	yield from gdata.add_rows_to_spreadsheet(SPREADSHEET, [
		format_row(highlight["title"], highlight["description"], highlight["video"],
			 highlight["time"] - highlight["video"]["recorded_at"], highlight["nick"])
		for highlight in highlights
	])
	delete_staged_highlights(highlights)
示例#11
0
def get_status_msg(lrrbot):
    messages = []
    stream_info = twitch.get_info()
    if stream_info and stream_info.get('live'):
        game_id = lrrbot.get_game_id()
        show_id = lrrbot.get_show_id()

        shows = lrrbot.metadata.tables["shows"]
        games = lrrbot.metadata.tables["games"]
        game_per_show_data = lrrbot.metadata.tables["game_per_show_data"]
        with lrrbot.engine.begin() as conn:
            show = conn.execute(
                sqlalchemy.select([shows.c.name
                                   ]).where(shows.c.id == show_id).where(
                                       shows.c.string_id != "")).first()
            if show is not None:
                show, = show

            if game_id is not None:
                game, = conn.execute(
                    sqlalchemy.select([
                        sqlalchemy.func.coalesce(
                            game_per_show_data.c.display_name, games.c.name)
                    ]).select_from(
                        games.outerjoin(
                            game_per_show_data,
                            (game_per_show_data.c.game_id == games.c.id) &
                            (game_per_show_data.c.show_id == show_id))).where(
                                games.c.id == game_id)).first()
            else:
                game = None

        if game and show:
            messages.append("Currently playing %s on %s." % (game, show))
        elif game:
            messages.append("Currently playing %s." % game)
        elif show:
            messages.append("Currently showing %s." % show)
        messages.append(uptime_msg(stream_info))
    else:
        messages.append(
            googlecalendar.get_next_event_text(googlecalendar.CALENDAR_LRL))
    if 'advice' in storage.data['responses']:
        messages.append(
            random.choice(storage.data['responses']['advice']['response']))
    return ' '.join(messages)
示例#12
0
文件: misc.py 项目: andreasots/lrrbot
def get_status_msg(lrrbot):
	messages = []
	stream_info = twitch.get_info()
	if stream_info and stream_info.get('live'):
		game_id = lrrbot.get_game_id()
		show_id = lrrbot.get_show_id()

		shows = lrrbot.metadata.tables["shows"]
		games = lrrbot.metadata.tables["games"]
		game_per_show_data = lrrbot.metadata.tables["game_per_show_data"]
		with lrrbot.engine.begin() as conn:
			show = conn.execute(sqlalchemy.select([shows.c.name])
				.where(shows.c.id == show_id)
				.where(shows.c.string_id != "")).first()
			if show is not None:
				show, = show

			if game_id is not None:
				game, = conn.execute(sqlalchemy.select([
					sqlalchemy.func.coalesce(game_per_show_data.c.display_name, games.c.name)
				]).select_from(
					games.outerjoin(game_per_show_data,
						(game_per_show_data.c.game_id == games.c.id) &
							(game_per_show_data.c.show_id == show_id))
				).where(games.c.id == game_id)).first()
			else:
				game = None

		if game and show:
			messages.append("Currently playing %s on %s." % (game, show))
		elif game:
			messages.append("Currently playing %s." % game)
		elif show:
			messages.append("Currently showing %s." % show)
		messages.append(uptime_msg(stream_info))
	else:
		messages.append(googlecalendar.get_next_event_text(googlecalendar.CALENDAR_LRL))
	if 'advice' in storage.data['responses']:
		messages.append(random.choice(storage.data['responses']['advice']['response']))
	return ' '.join(messages)
示例#13
0
 async def wrapper(self, conn, event, respond_to, *args, **kwargs):
     if event.type == "pubmsg" and twitch.get_info()["live"]:
         source = irc.client.NickMask(event.source)
         respond_to = source.nick
     return await func(self, conn, event, respond_to, *args, **kwargs)