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'])
def link_discord(mtgo_username: str, discord_id: int) -> Person: person_id = deck.get_or_insert_person_id(mtgo_username, None, None) p = load_person_by_id(person_id) if p.discord_id is not None: raise AlreadyExistsException( 'Player with mtgo username {mtgo_username} already has discord id {old_discord_id}, cannot add {new_discord_id}' .format(mtgo_username=mtgo_username, old_discord_id=p.discord_id, new_discord_id=discord_id)) sql = 'UPDATE person SET discord_id = %s WHERE id = %s' db().execute(sql, [discord_id, p.id]) return p