Example #1
0
def person_status():
    r = {
        'mtgo_username':
        auth.mtgo_username(),
        'discord_id':
        auth.discord_id(),
        'admin':
        session.get('admin', False),
        'demimod':
        session.get('demimod', False),
        'hide_intro':
        request.cookies.get('hide_intro', False) or auth.hide_intro()
        or auth.mtgo_username() or auth.discord_id(),
        'in_guild':
        session.get('in_guild', False),
    }
    if auth.mtgo_username():
        d = guarantee_at_most_one_or_retire(
            league.active_decks_by(auth.mtgo_username()))
        if d is not None:
            r['deck'] = {
                'name': d.name,
                'url': url_for('deck', deck_id=d.id),
                'wins': d.get('wins', 0),
                'losses': d.get('losses', 0)
            }
    if r['admin'] or r['demimod']:
        r['archetypes_to_tag'] = len(deck.load_decks('NOT d.reviewed'))
    return return_json(r)
def league_run_api(person):
    decks = league.active_decks_by(person)
    if len(decks) == 0:
        return return_json(None)

    run = guarantee_at_most_one_or_retire(decks)

    decks = league.active_decks()
    already_played = [m.opponent_deck_id for m in match.get_matches(run)]
    run.can_play = [d.person for d in decks if d.person != person and d.id not in already_played]

    return return_json(run)
def drop(person):
    error = validate_api_key()
    if error:
        return error

    decks = league.active_decks_by(person)
    if len(decks) == 0:
        return return_json(generate_error('NO_ACTIVE_RUN', 'That person does not have an active run'))

    run = guarantee.exactly_one(decks)

    league.retire_deck(run)
    result = {'success':True}
    return return_json(result)
Example #4
0
def person_status():
    r = {
        'mtgo_username': auth.mtgo_username(),
        'discord_id': auth.discord_id(),
        'admin': session.get('admin', False)
    }
    if auth.mtgo_username():
        d = guarantee_at_most_one_or_retire(
            league.active_decks_by(auth.mtgo_username()))
        if d is not None:
            r['deck'] = {
                'name': d.name,
                'url': url_for('deck', deck_id=d.id),
                'wins': d.get('wins', 0),
                'losses': d.get('losses', 0)
            }
    return return_json(r)
Example #5
0
def person_status() -> Response:
    username = auth.mtgo_username()
    r = {
        'mtgo_username': username,
        'discord_id': auth.discord_id(),
        'admin': session.get('admin', False),
        'demimod': session.get('demimod', False),
        'hide_intro': request.cookies.get('hide_intro', False) or auth.hide_intro() or username or auth.discord_id(),
        'in_guild': session.get('in_guild', False),
        }
    if username:
        d = guarantee_at_most_one_or_retire(league.active_decks_by(username))
        if d is not None:
            r['deck'] = {'name': d.name, 'url': url_for('deck', deck_id=d.id), 'wins': d.get('wins', 0), 'losses': d.get('losses', 0)} # type: ignore
    if r['admin'] or r['demimod']:
        r['archetypes_to_tag'] = len(deck.load_decks('NOT d.reviewed'))
    active_league = league.active_league()
    if active_league:
        time_until_league_end = active_league.end_date - datetime.datetime.now(tz=datetime.timezone.utc)
        if time_until_league_end <= datetime.timedelta(days=2):
            r['league_end'] = dtutil.display_time(time_until_league_end/datetime.timedelta(seconds=1), granularity=2)
    return return_json(r)