示例#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 deck(deck_id):
    d = ds.load_deck(deck_id)
    if auth.discord_id() and auth.logged_person() is None and not d.is_person_associated():
        ps.associate(d, auth.discord_id())
        p = ps.load_person_by_discord_id(auth.discord_id())
        auth.log_person(p)

    view = Deck(d, auth.logged_person())
    return view.page()
 def link_discord(self) -> None:
     did = auth.discord_id()
     if did is None:
         self.form.errors.mtgo_username = '******'
         return
     try:
         self.person = person.link_discord(self.form['mtgo_username'], did)
     except AlreadyExistsException:
         self.form.errors.mtgo_username = '******'.format(
             mtgo_username=self.form['mtgo_username'])
 def link_discord(self):
     p = deck.get_or_insert_person_id(self.form['mtgo_username'], None,
                                      None)
     p = person.load_person(p)
     if p.discord_id is None:
         sql = 'UPDATE person SET discord_id = %s WHERE id = %s'
         db().execute(sql, [auth.discord_id(), p.id])
         self.person = p
     else:
         self.form.errors.mtgo_username = '******'.format(
             mtgo_username=self.form['mtgo_username'])
示例#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)
示例#6
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)
 def __init__(self):
     self.mtgo_name = auth.logged_person_mtgo_username()
     self.person = person.load_person_by_discord_id(auth.discord_id())
     self.form = Container()
     for k in request.form.keys():
         self.form[k] = request.form[k]
     self.form.errors = Container()
     if self.person:
         if self.form.get(
                 'to_username', None
         ) is None and self.person.tappedout_username is not None:
             self.form['to_username'] = self.person.tappedout_username
             self.disable_to = True
         if self.form.get(
                 'gf_username', None
         ) is None and self.person.mtggoldfish_username is not None:
             self.form['gf_username'] = self.person.mtggoldfish_username
             self.disable_gf = True
     self.validate()
 def __init__(self) -> None:
     super().__init__()
     self.mtgo_name = auth.mtgo_username()
     self.person = person.maybe_load_person_by_discord_id(auth.discord_id())
     self.form = Container()
     for k in request.form.keys():  # type: ignore
         self.form[k] = request.form[k].strip()
     self.form.errors = Container()
     if self.person and self.person.mtgo_username:
         if self.form.get(
                 'to_username', None
         ) is None and self.person.tappedout_username is not None:
             self.form['to_username'] = self.person.tappedout_username
             self.disable_to = True
         if self.form.get(
                 'gf_username', None
         ) is None and self.person.mtggoldfish_username is not None:
             self.form['gf_username'] = self.person.mtggoldfish_username
             self.disable_gf = True
     self.process()
示例#9
0
def deck(deck_id: int) -> str:
    d = ds.load_deck(deck_id)
    view = Deck(d, auth.person_id(), auth.discord_id())
    return view.page()