Beispiel #1
0
def make_wager(team_name, username, description, points, position,  minutes):
    if 1 > points:
        return f"`{points}` is a terrible failure. All wagers must be positive integers.\n" \
               f"Usage: `!wager <points> <Description>`\n" \
               f"If you'd like to bet something will not happen reflect that in the description."
    if points > 5001:
        return f"`{points}` is a terrible failure. All wagers must be positive integers less than 5001.\n" \
               f"Usage: `!wager <points> <Description>`\n" \
               f"If you'd like to bet something will not happen reflect that in the description."

    team, user = get_team_user(team_name, username)

    existing_wager = team.wager_exists(description)
    exists = False
    for w in existing_wager:
        if w.description == description:
            exists = True
            return f"Wager: `#{w.id}` {w.description} already exists.\n" \
                   f"```Usage: !bet <#wager> <points> <True/False>```"

    if not exists:
        end_time = datetime.now() + timedelta(minutes=minutes)
        bet = Bet(points=points, position=position)
        wager = Wager(team_id=team.id, description=description, points=points, start_time=datetime.now(), end_time=end_time)
        bet.wager = wager
        user.bets.append(bet)
        s.commit()
        msg = f'Wager: `#{wager.id}`\n"{wager.description}"\n' \
              f'{get_wager_bets(wager)}'
        s.close()
        payload = {"msg": msg, "wager_id": wager.id}
        return payload
Beispiel #2
0
def make_bet(team_name, username, points, position, wager_id):
    if points < 1:
        return "You can't bet negative points."
    if points > 5000:
        return "5000 is the max bet."
    team, user = get_team_user(team_name, username)

    wager = s.query(Wager).get(wager_id)
    msg = ""
    if wager:
        if wager.team_id != team.id:
            return f'This team is not able to access wager `#{wager.id}`.'
        if wager.is_closed:
            return f'Wager: `#{wager.id}` "{wager.description}" is closed for betting.'

        if bet := wager.already_bet(user):
            print(bet)
            return f"Wager `#{wager.id}`: {wager.description}\n" \
                   f"{get_wager_bets(wager)}" \
                   # f"\n\n{user.username} already wagered `{bet.points}` `#{wager.id}` will be `{bet.position}`.\n"
        if points > wager.bets[0].points:
            return f"You can't bet more than {wager.bets[0].points} on wager `#{wager.id}`"
        else:
            bet = Bet(points=points, position=position)
            bet.wager = wager
            bet.user = user
            s.add(bet)
            s.commit()
            msg += f'Wager: `#{wager.id}` "{wager.description}"\n'
            msg += get_wager_bets(wager)
            # msg += f'\n@{user.username} your bet has been recorded.\n'
            s.close()
            return msg