Beispiel #1
0
def do_bet(message):
    if message.chat.id != message.from_user.id:
        bot.send_message(message.chat.id,
                         _('This command can not be used on group chats.'))
        return
    get_user(message)
    chat_id = message.chat.id
    query = get_matches()
    matches = query.filter(Match.score1 == None).filter(
        Match.start_date > datetime.datetime.now()).all()
    query = get_bets()
    user_bets = query.filter(Bet.player_id == message.from_user.id).all()
    markup = types.ReplyKeyboardMarkup(row_width=len(matches))
    to_bet = 0
    for m in matches:
        skip = 0
        for b in user_bets:
            if b.match == m.id:
                skip = 1
                break
        if skip == 1:
            continue
        else:
            to_bet += 1
        markup.add(str(m.id) + ' - ' + m.team1 + ' - ' + m.team2)
    if (not matches or not to_bet):
        bot.send_message(
            message.chat.id,
            _('No matches available (Or you already bet on all).'))
        return
    markup.add(_('Cancel'))
    bot.send_message(chat_id, _('Choose a match:'), reply_markup=markup)
    userStep[message.from_user.id] = 51
Beispiel #2
0
def set_bet_db(message):
    chat_id = message.chat.id
    markup = types.ReplyKeyboardHide()
    bot.send_message(chat_id,
                     _('Winner correctly selected.'),
                     reply_markup=markup)
    query = get_matches()
    match = query.filter(
        Match.id == to_winner[message.from_user.id]['id']).first()
    match.score1 = to_winner[message.from_user.id]['score1']
    match.score2 = message.text

    update()
    query = get_bets()
    bets = query.filter(
        Bet.match == to_winner[message.from_user.id]['id']).all()
    for b in bets:
        query = get_ranking()
        ranking = query.filter(Ranking.player_id == b.player_id).first()
        if not ranking:
            ranking = Ranking(player_id=b.player_id)
            add(ranking)
        ranking.total += 1
        winner = ('team1' if int(message.text) < int(
            to_winner[message.from_user.id]['score1']) else 'team2')
        if to_winner[message.from_user.id][winner] == b.bet:
            ranking.wins += 1
        update()
    userStep[message.from_user.id] = None
Beispiel #3
0
def confirm_match_choose(message):
    if (message.text == 'cancel' or message.text == 'Cancel'):
        markup = types.ReplyKeyboardHide()
        bot.send_message(message.chat.id,
                         _('Action cancelled.'),
                         reply_markup=markup)
        userStep[message.from_user.id] = None
        return
    chat_id = message.chat.id
    markup = types.ReplyKeyboardHide()
    bot.send_message(chat_id,
                     _('Match selected correctly.'),
                     reply_markup=markup)
    mid = message.text.split(' ')
    query = get_matches()
    match = query.filter(Match.id == int(mid[0])).one()
    to_winner[message.from_user.id] = {
        'id': match.id,
        'team1': match.team1,
        'team2': match.team2
    }
    markup = types.ForceReply(selective=False)
    bot.send_message(chat_id,
                     match.team1 + ' ' + _('Score:'),
                     reply_markup=markup)
    userStep[message.from_user.id] = 32
Beispiel #4
0
def list_bets(message):
    query = get_matches()
    matches = query.filter(Match.score1 == None).all()
    text = ''
    query = get_bets()
    for m in matches:
        bets = query.filter(Bet.match == m.id).all()
        date = m.start_date.strftime('%d-%m-%Y')
        hour = m.start_date.strftime('%H:%M')
        bets1 = 0
        bets2 = 0
        for b in bets:
            if b.bet == m.team1:
                bets1 += 1
            elif b.bet == m.team2:
                bets2 += 1
        odd1 = 0
        odd2 = 0
        if bets1 or bets2:
            odd1 = bets1 * 100 / (bets1 + bets2)
            odd2 = bets2 * 100 / (bets1 + bets2)
        text += (emoji(':calendar:') + date + ' ' + emoji(':clock1:') + hour +
                 ' ' + emoji(' :fast_forward:') + ' *' + m.team1 + '* ' +
                 str(odd1) + '%' + ' ' + emoji(':vs:') + ' ' + str(odd2) +
                 '% *' + m.team2 + '*\n')
    if (not matches):
        bot.send_message(message.chat.id, _('No matches available.'))
    else:
        bot.send_message(message.chat.id, text, parse_mode='markdown')
Beispiel #5
0
def del_match_db(message):
    chat_id = message.chat.id
    markup = types.ReplyKeyboardHide()
    match = message.text.split(' ')
    try:
        response = _("Match correctly deleted.")
        query = get_matches()
        query.filter(Match.id == int(match[0])).delete()
        delete(Match, Match.id == int(match[0]))
    except ValueError:
        response = _("Action canceled")
    bot.send_message(chat_id, response, reply_markup=markup)
    userStep[message.from_user.id] = None
Beispiel #6
0
def mybets(message):
    query = get_bets()
    bets = query.filter(Bet.player_id == message.from_user.id).all()
    text = ''
    query = get_matches()
    for b in bets:
        m = query.filter(Match.id == b.match).first()
        if m and (m.start_date > datetime.datetime.now() or m.score1 == None):
            text += (m.team1 + ' ' + emoji(':vs:') + ' ' + m.team2 + ' - ' +
                     emoji(':video_game:') + ' <b>' + b.bet + '</b>\n')
    if (not bets or not text):
        bot.send_message(message.chat.id, _('No bets available.'))
    else:
        bot.send_message(message.chat.id, text, parse_mode='html')
Beispiel #7
0
def do_bet_winner(message):
    chat_id = message.chat.id
    mid = message.text.split(' ')
    query = get_matches()
    try:
        match = query.filter(Match.id == int(mid[0])).one()
        to_bet[message.from_user.id] = mid
        markup = types.ReplyKeyboardMarkup(row_width=2)
        markup.add(match.team1)
        markup.add(match.team2)
        bot.send_message(chat_id, _('Choose a winner:'), reply_markup=markup)
        userStep[message.from_user.id] = 52
    except ValueError:
        markup = types.ReplyKeyboardHide()
        bot.send_message(message.chat.id,
                         _('Action cancelled.'),
                         reply_markup=markup)
Beispiel #8
0
def del_match(message):
    chat_id = message.chat.id

    if message.from_user.id not in administrators:
        bot.send_message(message.chat.id, _('You can not use this command.'))
        return
    if chat_id != message.from_user.id:
        bot.send_message(message.chat.id,
                         _('This command can not be used on group chats.'))
        return
    query = get_matches()
    matches = query.filter(Match.score1 == None).all()
    markup = types.ReplyKeyboardMarkup(row_width=len(matches))
    for m in matches:
        markup.add(str(m.id) + ' ' + m.team1 + ' ' + m.team2)
    if (not matches):
        bot.send_message(message.chat.id, _('No matches available.'))
        return
    markup.add(_('Cancel'))
    bot.send_message(chat_id, _("Choose a match:"), reply_markup=markup)
    userStep[message.from_user.id] = 41
Beispiel #9
0
def history(message):
    query = get_matches()
    matches = query.filter(Match.start_date > datetime.datetime.now() -
                           datetime.timedelta(days=5)).filter(
                               Match.score1 != None).all()
    text = ''
    count = 0
    for m in matches:
        if count == 10:
            return
        count += 1
        winner = 'TBD'
        score1 = str(m.score1) + ' ' if m.score1 or m.score1 == 0 else ''
        score2 = str(m.score2) + ' ' if m.score2 or m.score1 == 0 else ''
        if m.score2 or m.score2 == 0 and m.score1 or m.score1 == 0:
            winner = (m.team1 if m.score2 < m.score1 else m.team2)
        text += ('<b> ' + score1 + '</b> ' + m.team1 + ' ' + emoji(':vs:') +
                 ' <b>' + score2 + '</b> ' + ' ' + m.team2 + ' - ' +
                 emoji(':trophy:') + ' <b>' + winner + '</b>\n')
    if (not matches):
        bot.send_message(message.chat.id, _('No bets available.'))
    else:
        bot.send_message(message.chat.id, text, parse_mode='html')