Пример #1
0
def witness_match(args):
    if len(args) != 5:
        return 'Usage: /witness @winner @loser winner_wins loser_wins'

    witness = User.get_user(slack_id=args[0])
    winner = User.get_user(slack_id=args[1])
    loser = User.get_user(slack_id=args[2])
    winner_wins = int(args[3])
    loser_wins = int(args[4])

    if witness is None:
        return 'You have not yet logged into ranker, or have not yet linked slack to eac'
    if winner is None:
        return 'That winner has not yet logged into ranker, or have not yet linked slack to eac'
    if loser is None:
        return 'That loser has not yet logged into ranker, or have not yet linked slack to eac'

    data = {
        "username": witness.username,
        "winner": winner.username,
        "loser": loser.username,
        "winner_wins": winner_wins,
        "loser_wins": loser_wins,
        "witness": witness.username
    }

    token = rotate_token()
    response = post(host_uri + url_for("matches.witness_match"),
                    json=data,
                    auth=OidcAuth(token, witness.username))
    return response.content
Пример #2
0
def cancel_match(args):
    if len(args) != 2:
        return "Usage: /cancel @opponent"

    challenged = User.get_user(slack_id=args[0])
    challenger = User.get_user(slack_id=args[1])

    if challenged is None:
        return "Your opponent's slack id is not linked to a ranker player!"
    if challenger is None:
        return "Your slack id is not linked to a ranker player!"

    data = {
        "challenged": challenged.username,
        "challenger": challenger.username
    }

    token = rotate_token()
    response = post(host_uri + url_for('matches.cancel_match'),
                    json=data,
                    auth=OidcAuth(token, challenged.username))
    return response.text
Пример #3
0
def accept_match(args):
    if len(args) != 2:
        return "Usage: /accept @opponent"

    challenged = User.get_user(slack_id=args[0])
    challenger = User.get_user(slack_id=args[1])

    if challenged is None:
        return "You have not yet logged into ranker, or have not yet linked slack to eac"
    if challenger is None:
        return "Your opponent has not yet logged into ranker, or have not yet linked slack to eac"

    data = {
        "challenged": challenged.username,
        "challenger": challenger.username
    }

    token = rotate_token()
    response = post(host_uri + url_for('matches.accept_match'),
                    json=data,
                    auth=OidcAuth(token, challenged.username))
    return response.text
Пример #4
0
def create_user(username, first_name, last_name, profile_img, **kwargs):
    try:
        user = User(username=username,
                    first_name=first_name,
                    last_name=last_name,
                    profile_img=profile_img,
                    twitch_id=kwargs.get("twitch_id"),
                    twitter_id=kwargs.get("twitter_id"),
                    slack_id=kwargs.get("slack_id"))

        db.session.add(user)
        db.session.commit()
    except SQLAlchemyError as err:
        raise err
    return user
Пример #5
0
def new_witness():
    try:
        content = get_request_json(username_schema)
    except ValidationError as error:
        return make_response(error, 400)

    username = content["username"]

    try:
        user = User.get_user(username=username)
        user.witness = True
        db.session.add(user)
        db.session.commit()
    except SQLAlchemyError as err:
        logging.error("Error: Could not create witness: ", err)
        return make_response(
            "Sorry, that witness could not be added. Check your fields and try again",
            400)
    return make_response("{0} has been made a witness".format(user.username),
                         200)
Пример #6
0
def create_score(username, season_id):
    user = User.get_user(username)
    season = Season.get_season(season_id)

    if not user:
        raise ValueError(
            "Error: Cannot create score. User '{0}' not found".format(
                username))
    if not season:
        raise ValueError(
            "Error: Cannot create score. Season '{0}' not found".format(
                season_id))

    try:
        score = Score(user=user, season=season)

        db.session.add(score)
        db.session.commit()
    except SQLAlchemyError as err:
        raise err
    return score
Пример #7
0
def get_witnesses():
    witnesses = User.get_user(witness=True)
    return users_schema.dumps(witnesses)
Пример #8
0
 def validates_challenged(self, value):
     if not User.get_user(username=value):
         raise ValidationError(
             'You are not a ranker player. Login to signup')
Пример #9
0
 def validates_challenger(self, value):
     if not User.get_user(username=value):
         raise ValidationError('Your opponent is not a ranker player!')
Пример #10
0
 def validate_challenger(self, value):
     if not User.get_user(username=value):
         raise ValidationError('You are not a ranker user')
Пример #11
0
 def validate_user_id(self, value):
     if not User.get_user(slack_id=value):
         raise ValidationError(
             'Your Slack ID is not linked to a Ranker player. Use eac to link'
         )