Esempio n. 1
0
def nextfan(lrrbot, conn, event, respond_to, timezone):
	"""
	Command: !nextfan
	Section: info

	Gets the next scheduled stream from the fan-streaming calendar
	"""
	conn.privmsg(respond_to, googlecalendar.get_next_event_text(googlecalendar.CALENDAR_FAN, tz=timezone, include_current=True))
Esempio n. 2
0
def nextfan(lrrbot, conn, event, respond_to, timezone):
	"""
	Command: !nextfan
	Section: info

	Gets the next scheduled stream from the fan-streaming calendar
	"""
	conn.privmsg(respond_to, googlecalendar.get_next_event_text(googlecalendar.CALENDAR_FAN, tz=timezone, include_current=True))
Esempio n. 3
0
def next(lrrbot, conn, event, respond_to, timezone):
	"""
	Command: !next
	Section: info

	Gets the next scheduled stream from the LoadingReadyLive calendar

	Can specify a timezone, to show stream in your local time, eg: !next America/New_York

	If no time zone is specified, times will be shown in Moonbase time.
	"""
	if DESERTBUS_PRESTART < datetime.datetime.now(datetime.timezone.utc) < DESERTBUS_END:
		# If someone says !next before/during Desert Bus, plug that instead
		desertbus(lrrbot, conn, event, respond_to, timezone)
	else:
		conn.privmsg(respond_to, googlecalendar.get_next_event_text(googlecalendar.CALENDAR_LRL, tz=timezone))
Esempio n. 4
0
def next(lrrbot, conn, event, respond_to, timezone):
	"""
	Command: !next
	Section: info

	Gets the next scheduled stream from the LoadingReadyLive calendar

	Can specify a timezone, to show stream in your local time, eg: !next America/New_York

	If no time zone is specified, times will be shown in Moonbase time.
	"""
	if DESERTBUS_PRESTART < datetime.datetime.now(datetime.timezone.utc) < DESERTBUS_END:
		# If someone says !next before/during Desert Bus, plug that instead
		desertbus(lrrbot, conn, event, respond_to, timezone)
	else:
		conn.privmsg(respond_to, googlecalendar.get_next_event_text(googlecalendar.CALENDAR_LRL, tz=timezone))
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
0
async def load_session(include_url=True, include_header=True):
    """
	Get the login session information from the cookies.

	Includes all the information needed by the master.html template.
	"""
    user_id = flask.session.get('id')
    user_name = flask.session.get('user')
    if user_id is None and user_name is not None:
        # Upgrade old session
        with server.db.engine.begin() as conn:
            query = insert(users) \
             .values(id=sqlalchemy.bindparam("_id")) \
             .returning(users.c.id)
            query = query.on_conflict_do_update(
                index_elements=[users.c.id],
                set_={
                    'name': query.excluded.name,
                    'display_name': query.excluded.display_name,
                },
            )
            user_id, = conn.execute(query, twitch.get_user(user_name)).first()
        flask.session["id"] = user_id
    if 'user' in flask.session:
        del flask.session["user"]
    if 'apipass' in flask.request.values and flask.request.values[
            'apipass'] in from_apipass:
        user_id = from_apipass[flask.request.values["apipass"]]

    session = {}
    if include_url:
        session['url'] = flask.request.url
    else:
        session['url'] = None
    if include_header:
        session['header'] = await common.rpc.bot.get_header_info()
        if 'current_game' in session['header']:
            games = server.db.metadata.tables["games"]
            shows = server.db.metadata.tables["shows"]
            stats = server.db.metadata.tables["stats"]
            game_per_show_data = server.db.metadata.tables[
                "game_per_show_data"]
            game_stats = server.db.metadata.tables["game_stats"]
            game_votes = server.db.metadata.tables["game_votes"]
            disabled_stats = server.db.metadata.tables["disabled_stats"]
            with server.db.engine.begin() as conn:
                game_id = session['header']['current_game']['id']
                show_id = session['header']['current_show']['id']
                session['header']['current_game']['display'], = 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()

                session['header']['current_show']['name'], = conn.execute(
                    sqlalchemy.select([
                        shows.c.name,
                    ]).where(shows.c.id == show_id)).first()

                good = sqlalchemy.cast(
                    sqlalchemy.func.sum(
                        sqlalchemy.cast(game_votes.c.vote,
                                        sqlalchemy.Integer)),
                    sqlalchemy.Numeric)
                rating = conn.execute(
                    sqlalchemy.select([
                        (100 * good /
                         sqlalchemy.func.count(game_votes.c.vote)),
                        good,
                        sqlalchemy.func.count(game_votes.c.vote),
                    ]).where(game_votes.c.game_id == game_id).where(
                        game_votes.c.show_id == show_id)).first()
                if rating[0] is not None and rating[1] is not None:
                    session['header']['current_game']["rating"] = {
                        'perc': rating[0],
                        'good': rating[1],
                        'total': rating[2],
                    }
                stats_query = sqlalchemy.select([
                 game_stats.c.count,
                 game_data.stat_plural(stats, game_stats.c.count)
                ]).select_from(game_stats
                 .join(stats, stats.c.id == game_stats.c.stat_id)
                ).where(game_stats.c.game_id == game_id) \
                 .where(game_stats.c.show_id == show_id) \
                 .where(~sqlalchemy.exists(sqlalchemy.select([1])
                  .where(disabled_stats.c.stat_id == game_stats.c.stat_id)
                  .where(disabled_stats.c.show_id == game_stats.c.show_id)
                 )) \
                 .order_by(game_stats.c.count.desc())
                session['header']['current_game']['stats'] = [{
                    'count': count,
                    'type': type,
                } for count, type in conn.execute(stats_query)]

        if not session['header']['is_live']:
            session['header'][
                'nextstream'] = googlecalendar.get_next_event_text(
                    googlecalendar.CALENDAR_LRL)

    if user_id is not None:
        users = server.db.metadata.tables["users"]
        patreon_users = server.db.metadata.tables["patreon_users"]
        with server.db.engine.begin() as conn:
            query = sqlalchemy.select([
                users.c.name,
                sqlalchemy.func.coalesce(users.c.display_name, users.c.name),
                users.c.twitch_oauth, users.c.is_sub, users.c.is_mod,
                users.c.autostatus, users.c.patreon_user_id
            ]).where(users.c.id == user_id)
            name, display_name, token, is_sub, is_mod, autostatus, patreon_user_id = conn.execute(
                query).first()
            session['user'] = {
                "id": user_id,
                "name": name,
                "display_name": display_name,
                "twitch_oauth": token,
                "is_sub": is_sub,
                "is_mod": is_mod,
                "autostatus": autostatus,
                "patreon_user_id": patreon_user_id,
            }
    else:
        session['user'] = {
            "id": None,
            "name": None,
            "display_name": None,
            "twitch_oauth": None,
            "is_sub": False,
            "is_mod": False,
            "autostatus": False,
        }
    return session
Esempio n. 8
0
async def load_session(include_url=True, include_header=True):
	"""
	Get the login session information from the cookies.

	Includes all the information needed by the master.html template.
	"""
	user_id = flask.session.get('id')
	user_name = flask.session.get('user')
	if user_id is None and user_name is not None:
		# Upgrade old session
		user_id = flask.session["id"] = twitch.get_user(name=user_name).id
	if 'user' in flask.session:
		del flask.session["user"]
	if 'apipass' in flask.request.values and flask.request.values['apipass'] in from_apipass:
		user_id = from_apipass[flask.request.values["apipass"]]

	session = {}
	if include_url:
		session['url'] = flask.request.url
	else:
		session['url'] = None
	if include_header:
		session['header'] = await common.rpc.bot.get_header_info()
		if 'current_game' in session['header']:
			games = server.db.metadata.tables["games"]
			shows = server.db.metadata.tables["shows"]
			game_per_show_data = server.db.metadata.tables["game_per_show_data"]
			with server.db.engine.begin() as conn:
				game_id = session['header']['current_game']['id']
				show_id = session['header']['current_show']['id']
				session['header']['current_game']['display'], = 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()

				session['header']['current_show']['name'], = conn.execute(sqlalchemy.select([
					shows.c.name,
				]).where(shows.c.id == show_id)).first()

		if not session['header']['is_live']:
			session['header']['nextstream'] = googlecalendar.get_next_event_text(googlecalendar.CALENDAR_LRL)

	if user_id is not None:
		user_id = int(user_id)
		users = server.db.metadata.tables["users"]
		patreon_users = server.db.metadata.tables["patreon_users"]
		with server.db.engine.begin() as conn:
			query = sqlalchemy.select([
				users.c.name, sqlalchemy.func.coalesce(users.c.display_name, users.c.name), users.c.twitch_oauth,
				users.c.is_sub, users.c.is_mod, users.c.autostatus, users.c.patreon_user_id,
				users.c.stream_delay, users.c.chat_timestamps, users.c.chat_timestamps_24hr, users.c.chat_timestamps_secs
			]).where(users.c.id == user_id)
			name, display_name, token, is_sub, is_mod, autostatus, patreon_user_id, \
				stream_delay, chat_timestamps, chat_timestamps_24hr, chat_timestamps_secs = conn.execute(query).first()
			session['user'] = {
				"id": user_id,
				"name": name,
				"display_name": display_name,
				"twitch_oauth": token,
				"is_sub": is_sub,
				"is_mod": is_mod,
				"autostatus": autostatus,
				"patreon_user_id": patreon_user_id,
				"stream_delay": stream_delay,
				"chat_timestamps": chat_timestamps,
				"chat_timestamps_24hr": chat_timestamps_24hr,
				"chat_timestamps_secs": chat_timestamps_secs,
			}
	else:
		session['user'] = {
			"id": None,
			"name": None,
			"display_name": None,
			"twitch_oauth": None,
			"is_sub": False,
			"is_mod": False,
			"autostatus": False,
			"stream_delay": 10,
			"chat_timestamps": 0,
			"chat_timestamps_24hr": True,
			"chat_timestamps_secs": False,
		}
	return session
Esempio n. 9
0
async def load_session(include_url=True, include_header=True):
    """
	Get the login session information from the cookies.

	Includes all the information needed by the master.html template.
	"""
    user_id = flask.session.get('id')
    user_name = flask.session.get('user')
    if user_id is None and user_name is not None:
        # Upgrade old session
        user_id = flask.session["id"] = twitch.get_user(name=user_name).id
    if 'user' in flask.session:
        del flask.session["user"]
    if 'apipass' in flask.request.values and flask.request.values[
            'apipass'] in from_apipass:
        user_id = from_apipass[flask.request.values["apipass"]]

    session = {}
    if include_url:
        session['url'] = flask.request.url
    else:
        session['url'] = None
    if include_header:
        session['header'] = await common.rpc.bot.get_header_info()
        if 'current_game' in session['header']:
            games = server.db.metadata.tables["games"]
            shows = server.db.metadata.tables["shows"]
            game_per_show_data = server.db.metadata.tables[
                "game_per_show_data"]
            with server.db.engine.begin() as conn:
                game_id = session['header']['current_game']['id']
                show_id = session['header']['current_show']['id']
                session['header']['current_game']['display'], = 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()

                session['header']['current_show']['name'], = conn.execute(
                    sqlalchemy.select([
                        shows.c.name,
                    ]).where(shows.c.id == show_id)).first()

        if not session['header']['is_live']:
            session['header'][
                'nextstream'] = googlecalendar.get_next_event_text(
                    googlecalendar.CALENDAR_LRL)

    if user_id is not None:
        user_id = int(user_id)
        users = server.db.metadata.tables["users"]
        patreon_users = server.db.metadata.tables["patreon_users"]
        with server.db.engine.begin() as conn:
            query = sqlalchemy.select([
                users.c.name,
                sqlalchemy.func.coalesce(users.c.display_name, users.c.name),
                users.c.twitch_oauth, users.c.is_sub, users.c.is_mod,
                users.c.autostatus, users.c.patreon_user_id,
                users.c.stream_delay, users.c.chat_timestamps,
                users.c.chat_timestamps_24hr, users.c.chat_timestamps_secs
            ]).where(users.c.id == user_id)
            name, display_name, token, is_sub, is_mod, autostatus, patreon_user_id, \
             stream_delay, chat_timestamps, chat_timestamps_24hr, chat_timestamps_secs = conn.execute(query).first()
            session['user'] = {
                "id": user_id,
                "name": name,
                "display_name": display_name,
                "twitch_oauth": token,
                "is_sub": is_sub,
                "is_mod": is_mod,
                "autostatus": autostatus,
                "patreon_user_id": patreon_user_id,
                "stream_delay": stream_delay,
                "chat_timestamps": chat_timestamps,
                "chat_timestamps_24hr": chat_timestamps_24hr,
                "chat_timestamps_secs": chat_timestamps_secs,
            }
    else:
        session['user'] = {
            "id": None,
            "name": None,
            "display_name": None,
            "twitch_oauth": None,
            "is_sub": False,
            "is_mod": False,
            "autostatus": False,
            "stream_delay": 10,
            "chat_timestamps": 0,
            "chat_timestamps_24hr": True,
            "chat_timestamps_secs": False,
        }
    return session