Beispiel #1
0
def callback_worker(call):
    with connection.cursor() as cursor:
        sql = "SELECT * FROM `free_game_8_8` WHERE user_id=%s"
        cursor.execute(sql, call.message.chat.id)
        result = cursor.fetchall()
    if result[0]['user_select'] is None:
        if call.data == "paper_free_8_8":
            with connection.cursor() as cursor:
                sql = "UPDATE `free_game_8_8` SET user_select= %s WHERE user_id=%s"
                cursor.execute(sql, (1, result[0]['user_id']))
                sql = "UPDATE `free_game_8_8` SET enemy_select= %s WHERE enemy_id=%s"
                cursor.execute(sql, (1, result[0]['enemy_id']))
            connection.commit()
        elif call.data == 'scissors_free_8_8':
            with connection.cursor() as cursor:
                sql = "UPDATE `free_game_8_8` SET user_select= %s WHERE user_id=%s"
                cursor.execute(sql, (2, result[0]['second_user']))
                sql = "UPDATE `free_game_8_8` SET enemy_select= %s WHERE enemy_id=%s"
                cursor.execute(sql, (2, result[0]['enemy_id']))
            connection.commit()
        elif call.data == 'stone_free_8_8':
            with connection.cursor() as cursor:
                sql = "UPDATE `free_game_8_8` SET user_select= %s WHERE user_id=%s"
                cursor.execute(sql, (3, result[0]['second_user']))
                sql = "UPDATE `free_game_8_8` SET enemy_select= %s WHERE enemy_id=%s"
                cursor.execute(sql, (3, result[0]['enemy_id']))
            connection.commit()
    else:
        bot.send_message(call.message.chat.id,
                         text='Ви уже зробили свій вибір.')
Beispiel #2
0
def get_number_of_money(message):
    global number_of_money
    try:
        number_of_money = int(message.text)
    except ValueError:
        bot.send_message(message.from_user.id, text='Помилка при введені суми')
        bot.register_next_step_handler(message, callback=get_number_of_money)
    else:
        prices = [
            LabeledPrice(label='Поповнення рахунку',
                         amount=number_of_money * 100)
        ]
        bot.send_message(message.chat.id,
                         "Зараз платежі приймаються лише в тестовому режимі"
                         "\n\nВаш тестовий платіж:",
                         parse_mode='Markdown')
        bot.send_invoice(
            message.chat.id,
            title='Working Time Machine',
            description=' Поповнення рахунку',
            provider_token=provider_token,
            currency='UAH',
            photo_url=
            'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQP9bwtPnfeODkt-vJyBYpYDjStfrRMB5UQ4w&usqp=CAU',
            photo_height=0,  # !=0/None or picture won't be shown
            photo_width=0,
            photo_size=0,
            is_flexible=False,  # True If you need to set up Shipping Fee
            prices=prices,
            start_parameter='time-machine-example',
            invoice_payload='HAPPY FRIDAYS COUPON')
Beispiel #3
0
def callback_worker(call):
    if call.data == "free_game":
        bot.send_message(call.message.chat.id,
                         text='Оберіть: ',
                         reply_markup=free_game_keyboard())
    if call.data == 'free_game_1_1':
        free_game_1_1(call)
    if call.data == 'free_game_8_8':
        free_game_8_8(call)
Beispiel #4
0
def callback_worker(call):
    if call.data == 'add_some_money':
        bot.send_message(call.message.chat.id, text='Введіть суму:')
        bot.register_next_step_handler(call.message,
                                       callback=get_number_of_money)
    elif call.data == 'withdraw_money':
        bot.send_message(call.message.chat.id, text='Введіть суму:')
        bot.register_next_step_handler(call.message,
                                       callback=credit_card_input)
Beispiel #5
0
def turnir(call, person, price):
    with connection.cursor() as cursor:
        sql = "SELECT * FROM `users` WHERE id=%s"
        cursor.execute(sql, call.message.chat.id)
        result = cursor.fetchall()
    if result[0]['money'] < price:
        bot.send_message(
            call.message.chat.id,
            text=
            'На вашому рахунку недостатньо коштів, поповіність рахунок в профілі'
        )
    else:
        money = result[0]['money'] - price
        with connection.cursor() as cursor:
            sql = "UPDATE `users` SET money= %s WHERE id=%s"
            cursor.execute(sql, (money, call.message.chat.id))
        connection.commit()
        with connection.cursor() as cursor:
            sql = "SELECT * FROM `turnir` WHERE user_count=%s and price=%s"
            cursor.execute(sql, (person, price))
            result = cursor.fetchall()

        if len(result) == person - 1:
            with connection.cursor() as cursor:
                sql = "INSERT INTO `turnir` (`user_id`, `user_count`, `price`) VALUES (%s, %s, %s)"
                cursor.execute(sql, (call.message.chat.id, person, price))
            connection.commit()
            with connection.cursor() as cursor:
                sql = "SELECT * FROM `turnir` WHERE user_count=%s and price=%s"
                cursor.execute(sql, (person, price))
                result = cursor.fetchall()
            for u in result:
                with connection.cursor() as cursor:
                    sql = "DELETE FROM `turnir`  WHERE id=%s"
                    cursor.execute(sql, (u['id']))
                connection.commit()
            if person == 2:
                start_battle(result, price)
            else:
                send_message_one_ours_ready(result)
                time.sleep(3540)
                send_message_one_minutes_ready(result)
                time.sleep(60)
                start_battle(result, price)
        else:
            with connection.cursor() as cursor:
                sql = "INSERT INTO `turnir` (`user_id`, `user_count`, `price`) VALUES (%s, %s, %s)"
                cursor.execute(sql, (call.message.chat.id, person, price))
                sql = "UPDATE `users` SET money= %s WHERE id=%s"
                cursor.execute(sql, (money, call.message.chat.id))
            connection.commit()
            bot.send_message(
                call.message.chat.id,
                text=
                """Коли всі зберуться ми повідомимо тебе  за 0000 до початку.
            Поки чекаєш — заходь в наш - чат, де можна поспілкуватися з іншими учасниками!"""
            )
Beispiel #6
0
def callback_worker(call):
    global language
    if call.data == "language_ua":
        language = 'ua'
        bot.send_message(call.message.chat.id, text='Як вас називати?')
        bot.register_next_step_handler(call.message, callback=get_name)
    if call.data == 'language_ru':
        language = 'ru'
        bot.send_message(call.message.chat.id, text='Как вас называть?')
        bot.register_next_step_handler(call.message, callback=get_name)
Beispiel #7
0
def callback_worker(call):
    if call.data == "fastgame":
        bot.send_message(call.message.chat.id,
                         text='Оберіть: ',
                         reply_markup=fastgame_keyboard())
    if call.data == 'fastgame25':
        turnir(call, 8, 25)
    elif call.data == 'fastgame50':
        turnir(call, 8, 50)
    elif call.data == 'fastgame100':
        turnir(call, 8, 100)
Beispiel #8
0
def callback_worker(call):
    if call.data == "duel":
        bot.send_message(call.message.chat.id,
                         text='Оберіть: ',
                         reply_markup=duel_keyboard())
    if call.data == 'duel25':
        turnir(call, 2, 25)
    elif call.data == 'duel50':
        turnir(call, 2, 50)
    elif call.data == 'duel100':
        turnir(call, 2, 100)
    elif call.data == 'duel1000':
        turnir(call, 2, 1000)
Beispiel #9
0
def get_name(message):
    global name
    name = message.text
    try:
        with connection.cursor() as cursor:
            sql = "INSERT INTO `users` (`id`, `name`, `money`, `language`) VALUES (%s, %s, %s, %s)"
            cursor.execute(sql, (message.from_user.id, name, '0', language))
        connection.commit()
        with connection.cursor() as cursor:
            sql = "SELECT * FROM `users`"
            cursor.execute(sql)
    finally:
        bot.send_message(message.from_user.id,
                         text='Меню:',
                         reply_markup=main_menu())
Beispiel #10
0
def got_payment(message):
    with connection.cursor() as cursor:
        sql = "SELECT * FROM `users` WHERE id=%s"
        cursor.execute(sql, (message.from_user.id))
        result = cursor.fetchall()
        money = result[0][
            'money'] + message.successful_payment.total_amount / 100
        sql = "UPDATE `users` SET money= %s WHERE id=%s"
        cursor.execute(sql, (money, result[0]['id']))
    connection.commit()
    bot.send_message(message.chat.id,
                     'Ваш рахунок поповнено на `{} {}`'.format(
                         message.successful_payment.total_amount / 100,
                         'Тунгриків(need to change)'),
                     parse_mode='Markdown')
Beispiel #11
0
def credit_card_input(message):
    global number_of_money
    try:
        number_of_money = int(message.text)
    except ValueError:
        bot.send_message(message.from_user.id, text='Помилка при введені суми')
        bot.register_next_step_handler(message, callback=credit_card_input)
    else:
        with connection.cursor() as cursor:
            sql = "SELECT * FROM `users` WHERE id=%s"
            cursor.execute(sql, (message.from_user.id))
            result = cursor.fetchall()
        if result[0]['credit_card'] is None:
            bot.send_message(message.from_user.id,
                             text='Введіть кредитну карту')
            bot.register_next_step_handler(message, callback=withdraw_money)
        else:
            withdraw_money(message, default=False)
Beispiel #12
0
def free_game_8_8(call):
    try:
        with connection.cursor() as cursor:
            sql = "SELECT * FROM `free_game_8_8`"  # WHERE game_id is NULL"
            cursor.execute(sql)
            result = cursor.fetchall()
    finally:
        with connection.cursor() as cursor:
            sql = "SELECT * FROM `free_game_8_8` WHERE user_id = %s"
            cursor.execute(sql, call.message.chat.id)
            result_user_exist = cursor.fetchall()
        if result_user_exist.__len__() != 0:
            bot.send_message(
                call.message.chat.id,
                text="""Ви уже зареєстровані очікуйте всіх гравців""")
        else:
            if result.__len__() < 7:  #must be 7
                with connection.cursor() as cursor:
                    sql = "INSERT INTO `free_game_8_8` (`user_id`) VALUES (%s)"
                    cursor.execute(sql, call.message.chat.id)
                connection.commit()
                bot.send_message(
                    call.message.chat.id,
                    text=
                    """Коли всі зберуться ми повідомимо тебе  за годину до початку.
                Поки чекаєш — заходь в наш - чат, де можна поспілкуватися з іншими учасниками!"""
                )
            else:
                with connection.cursor() as cursor:
                    sql = "INSERT INTO `free_game_8_8` (`user_id`) VALUES (%s)"
                    cursor.execute(sql, call.message.chat.id)
                connection.commit()
                with connection.cursor() as cursor:
                    sql = "SELECT * FROM `free_game_8_8`"
                    cursor.execute(sql)
                    result = cursor.fetchall()
                time.sleep(3540)
                send_message_one_ours_ready(result)
                time.sleep(60)
                send_message_one_minutes_ready(result)
                start_battle(result)
Beispiel #13
0
def send_message_ready(dateOfStart, databaseName, gameId, users, pause):
    dt_object = datetime.fromtimestamp(dateOfStart)
    for u in users:
        bot.send_message(
            u['user_id'],
            text=
            f"""Розіграш на який ви зареєструвались, набрав необхідну кількість людей 
        Старт заплановано на : {dt_object}.""")
    time.sleep(pause)
    send_message_one_ours_ready(users)
    time.sleep(3540)
    send_message_one_minutes_ready(users)
    time.sleep(60)
    for u in users:
        bot.send_message(
            u['user_id'],
            text=
            f"""Турнір на який ви зареєструвалися розпочався, у вас є лише 30 
        секунд щоб зробити свій вибір""",
            reply_markup=play_keyboard_free_8_8())
    time.sleep(30)
    make_function(databaseName, gameId, play_keyboard_free_8_8, 0)
Beispiel #14
0
 def ended(self):
     if self.score1 == self.max_point:
         player_db.add_player(self.p1.chat__id, 'available',
                              self.p1.score + self.score1 - self.score2,
                              self.p1.user_name)
         bot.send_message(int(self.p1.chat__id), "Вітаю, ви виграли")
         bot.send_message(int(self.p2.chat__id),
                          "Наступного разу удача буде на вашій стороні...")
         x = player_db.find_player_by_id(self.p1.chat__id)
         next_level.append(x)
     elif self.score2 == self.max_point:
         bot.send_message(int(self.p1.chat__id),
                          "Наступного разу удача буде на вашій стороні...")
         bot.send_message(int(self.p2.chat__id), "Вітаю, ви виграли")
         player_db.add_player(self.p2.chat__id, 'available',
                              self.p2.score + self.score2 - self.score1,
                              self.p2.user_name)
         x = player_db.find_player_by_id(self.p2.chat__id)
         next_level.append(x)
Beispiel #15
0
    def play(self, selected1, selected2):
        bot.send_message(self.p1.chat__id,
                         "Супротивник Обрав " + str(arr[int(selected2) - 1]))
        bot.send_message(self.p2.chat__id,
                         "Супротивник Обрав " + str(arr[int(selected1) - 1]))
        if game_result(selected1, selected2) == 1:
            self.score1 += 1
        elif game_result(selected1, selected2) == -1:
            self.score2 += 1

        if self.score1 == self.max_point or self.score2 == self.max_point:
            self.ended()
        else:
            bot.send_message(self.p1.chat__id,
                             "Спробуйте свою удачу",
                             reply_markup=keyboard())
            bot.send_message(self.p2.chat__id,
                             "Спробуйте свою удачу",
                             reply_markup=keyboard())
Beispiel #16
0
def withdraw_money(message, default=True):
    global number_of_money
    if default:
        with connection.cursor() as cursor:
            sql = "SELECT * FROM `users` WHERE id=%s"
            cursor.execute(sql, (message.from_user.id))
            result = cursor.fetchall()
            money = result[0]['money'] - number_of_money
            reserv = result[0]['reserv_to_withdraw'] + number_of_money
            sql = "UPDATE `users` SET money= %s, reserv_to_withdraw = %s, credit_card = %s WHERE id=%s"
            cursor.execute(sql, (money, reserv, message.text, result[0]['id']))
        connection.commit()
        bot.send_message(message.from_user.id,
                         text='Запит на виведення коштів відправлено')
    else:
        try:
            number_of_money = int(message.text)
        except ValueError:
            bot.send_message(message.from_user.id,
                             text='Помилка при введені суми')
            bot.register_next_step_handler(message, callback=withdraw_money)
        else:
            with connection.cursor() as cursor:
                sql = "SELECT * FROM `users` WHERE id=%s"
                cursor.execute(sql, (message.from_user.id))
                result = cursor.fetchall()
            if result[0]['money'] < number_of_money:
                bot.send_message(message.from_user.id,
                                 text='У вас недостатньо коштів')
                bot.register_next_step_handler(message,
                                               callback=withdraw_money)
            else:
                with connection.cursor() as cursor:
                    money = result[0]['money'] - number_of_money
                    reserv = result[0]['reserv_to_withdraw'] + number_of_money
                    sql = "UPDATE `users` SET money= %s, reserv_to_withdraw = %s WHERE id=%s"
                    cursor.execute(sql, (money, reserv, result[0]['id']))
                connection.commit()
                bot.send_message(message.from_user.id,
                                 text='Запит на виведення коштів відправлено')
Beispiel #17
0
def check_user_win_db(users, database, key_board):
    result = ''
    for u in users:
        u_select = u['user_select']
        e_select = u['enemy_select']
        if u_select == 1 and e_select == 1:
            result = 'draw'
        elif u_select == 1 and e_select == 2:
            result = 'first_lose'
        elif u_select == 1 and e_select == 3:
            result = 'first_win'

        if u_select == 2 and e_select == 1:
            result = 'first_win'
        elif u_select == 2 and e_select == 2:
            result = 'draw'
        elif u_select == 2 and e_select == 3:
            result = 'first_lose'

        if u_select == 3 and e_select == 1:
            result = 'first_lose'
        elif u_select == 3 and e_select == 2:
            result = 'first_win'
        elif u_select == 3 and e_select == 3:
            result = 'draw'
        time.sleep(15)
        if result == 'first_win':
            bot.send_message(
                u['user_id'],
                text='Ви пройшли в наступний раунд( модифікувати)',
                reply_markup=key_board)
            with connection.cursor() as cursor:
                sql = f"UPDATE {database} SET user_select= %s, enemy_select = %s, enemy_id = %s WHERE user_id=%s"
                cursor.execute(sql, (None, None, None, u['user_id']))
            connection.commit()
        elif result == 'first_lose':
            bot.send_message(u['user_id'], text='Ви програли( модифікувати)')
            with connection.cursor() as cursor:
                sql = f"DELETE FROM {database} WHERE user_id=%s"
                cursor.execute(sql, (None, None, None, u['user_id']))
            connection.commit()
        elif result == 'draw':
            bot.send_message(u['user_id'],
                             text='Ви пройшли в наступний раунд( модифікувати)'
                             )  # TODO add draw function
            with connection.cursor() as cursor:
                sql = f"UPDATE {database} SET user_select= %s, enemy_select = %s, enemy_id = %s WHERE user_id=%s"
                cursor.execute(sql, (None, None, None, u['user_id']))
            connection.commit()
Beispiel #18
0
def free_game_1_1(call):
    try:
        with connection.cursor() as cursor:
            sql = "SELECT * FROM `current_game` WHERE id=(SELECT MAX(id) FROM `current_game`)"
            cursor.execute(sql)
            result = cursor.fetchall()
    finally:
        if result.__len__() != 0:
            if result[0]["second_user"] is None:
                if result[0]['user_id'] == call.message.chat.id:
                    bot.send_message(
                        call.message.chat.id,
                        text=
                        'Ви уже зареєстровані на гру. Очікуйте суперника....')
                else:
                    with connection.cursor() as cursor:
                        sql = "SELECT * FROM `current_game`"
                        cursor.execute(sql)
                        result = cursor.fetchall()
                    for u in result:
                        with connection.cursor() as cursor:
                            sql = "DELETE FROM `current_game`  WHERE id=%s"
                            cursor.execute(sql, u['id'])
                    connection.commit()
                    result.append({'user_id': call.message.chat.id})
                    start_battle(result, 0)

            else:
                with connection.cursor() as cursor:
                    sql = "INSERT INTO `current_game` (`user_id`) VALUES (%s)"
                    cursor.execute(sql, call.message.chat.id)
                connection.commit()
                bot.send_message(call.message.chat.id,
                                 text='Очікуйте суперника...')
        else:
            with connection.cursor() as cursor:
                sql = "INSERT INTO `current_game` (`user_id`) VALUES (%s)"
                cursor.execute(sql, call.message.chat.id)
            connection.commit()
            bot.send_message(call.message.chat.id,
                             text='Очікуйте суперника...')
Beispiel #19
0
def make_function(database, gameId, key_board, price):
    with connection.cursor() as cursor:
        sql = f"SELECT * FROM {database} WHERE game_id=%s"
        cursor.execute(sql, gameId)
        result = cursor.fetchall()
    check_user_vote(result, database, key_board)
    if result.__len__() > 2:
        u_select = result[0]['user_select']
        e_select = result[0]['enemy_select']
        if u_select == 1 and e_select == 1:
            result = 'draw'
        elif u_select == 1 and e_select == 2:
            result = 'first_lose'
        elif u_select == 1 and e_select == 3:
            result = 'first_win'

        if u_select == 2 and e_select == 1:
            result = 'first_win'
        elif u_select == 2 and e_select == 2:
            result = 'draw'
        elif u_select == 2 and e_select == 3:
            result = 'first_lose'

        if u_select == 3 and e_select == 1:
            result = 'first_lose'
        elif u_select == 3 and e_select == 2:
            result = 'first_win'
        elif u_select == 3 and e_select == 3:
            result = 'draw'
        time.sleep(15)
        if result == 'first_win':
            if 'free' in database:
                bot.send_message(result[0]['user_id'],
                                 text="Вітаю, ви перемогли!")
                bot.send_message(
                    result[0]['enemy_id'],
                    text=
                    "Не засмучуйся наступного разу удача буде на твоїй стороні!"
                )
            else:
                with connection.cursor() as cursor:
                    sql = "SELECT * FROM `users` WHERE id=%s"
                    cursor.execute(sql, (result[0]['user_id']))
                    result = cursor.fetchall()
                    money = result[0]['money'] + price
                    sql = "UPDATE `users` SET money= %s WHERE id=%s"
                    cursor.execute(sql, (money, result[0]['id']))
                connection.commit()
                bot.send_message(
                    result[0]['user_id'],
                    text=
                    "Вітаю, ви перемогли! Ващ виграш уже на вашому рахунку.")
                bot.send_message(
                    result[0]['enemy_id'],
                    text=
                    "Не засмучуйся, наступного разу удача буде на твоїй стороні!"
                )
        elif result == 'first_lose':
            if 'free' in database:
                bot.send_message(result[0]['enemy_id'],
                                 text="Вітаю, ви перемогли!")
                bot.send_message(
                    result[0]['user_id'],
                    text=
                    "Не засмучуйся наступного разу удача буде на твоїй стороні!"
                )
            else:
                with connection.cursor() as cursor:
                    sql = "SELECT * FROM `users` WHERE id=%s"
                    cursor.execute(sql, (result[0]['enemy_id']))
                    result = cursor.fetchall()
                    money = result[0]['money'] + price
                    sql = "UPDATE `users` SET money= %s WHERE id=%s"
                    cursor.execute(sql, (money, result[0]['id']))
                connection.commit()
                bot.send_message(
                    result[0]['enemy_id'],
                    text=
                    "Вітаю, ви перемогли! Ващ виграш уже на вашому рахунку.")
                bot.send_message(
                    result[0]['user_id'],
                    text=
                    "Не засмучуйся, наступного разу удача буде на твоїй стороні!"
                )
        elif result == 'draw':
            print(1)

    # TODO Check winner
    else:
        check_user_win_db(result, database, key_board)
Beispiel #20
0
def send_message_one_minutes_ready(users):
    for u in users:
        bot.send_message(u['user_id'], text=f"""Старт через годину.""")
Beispiel #21
0
def start_battle(users, price=0):
    full = len(users)
    for u in users:
        player_db.add_player(u['user_id'], 'in_battle', 0, 'enemy')
    i = 1
    x = 1
    xx = 1
    for u in users:
        if i % 2 == 1:
            x = player_db.find_player_by_id(u['user_id'])
        else:
            xx = player_db.find_player_by_id(u['user_id'])
            b = battle(x, xx, 1)
            battle_db.add_battle(b)
            bot.send_message(b.p1.chat__id,
                             text="Спробуйте свою удачу",
                             reply_markup=keyboard())
            bot.send_message(b.p2.chat__id,
                             text="Спробуйте свою удачу",
                             reply_markup=keyboard())
        i = i + 1

    while full != 1:
        time.sleep(10)
        if len(next_level) == full / 2:
            full = len(next_level)
            i = 1
            x = 1
            xx = 1
            for u in users:
                if i % 2 == 1:
                    x = u
                else:
                    xx = u
                    b = battle(x, xx, 1)
                    battle_db.add_battle(b)
                    bot.send_message(b.p1.chat__id,
                                     text="Спробуйте свою удачу",
                                     reply_markup=keyboard())
                    bot.send_message(b.p2.chat__id,
                                     text="Спробуйте свою удачу",
                                     reply_markup=keyboard())
        else:
            time.sleep(10)
            for key in wait_for_opp:
                wait_for_opp[key]['time'] += 10
                if wait_for_opp[key]['time'] >= 30:
                    try:
                        bat = battle_db.find(key)
                        if int(key) == int(bat.p1.chat__id):
                            bat.score1 = bat.max_point
                            bot.send_message(
                                int(bat.p1.chat__id),
                                "Суперник не грав більше 30 секунд, тож ви отримали шанс"
                            )
                            bot.send_message(
                                int(bat.p2.chat__id),
                                "Минуло більше 30 секунд з того часу, як ви зіграли і програли :("
                            )
                            bat.ended()
                        else:
                            bat.score2 = bat.max_point
                            bot.send_message(
                                int(bat.p2.chat__id),
                                "Суперник не грав більше 30 секунд, тож ви отримали шанс"
                            )
                            bot.send_message(
                                int(bat.p1.chat__id),
                                "Минуло більше 30 секунд з того часу, як ви зіграли і програли :("
                            )
                            bat.ended()
                        del wait_for_opp[key]
                        break
                    except Exception as e:
                        if 'Forbidden' in e:
                            try:
                                bot.send_message(bat.p1.chat__id,
                                                 "Суперник повністю здався")
                                bat.score1 = bat.max_point
                                bat.ended()
                                del wait_for_opp[key]
                            except:
                                bot.send_message(bat.p2.chat__id,
                                                 "Суперник повністю здався")
                                bat.score2 = bat.max_point
                                bat.ended()
                                del wait_for_opp[key]
        win = len(users) * price * 0.9
        with conn.cursor() as cursor:
            sql = "SELECT * FROM `users` WHERE id=%s"
            cursor.execute(sql, next_level[0].chat__id)
            result = cursor.fetchall()
            money = result[0]['money'] + win
            sql = "UPDATE `users` SET money= %s WHERE id=%s"
            cursor.execute(sql, (money, result[0]['id']))
        conn.commit()
Beispiel #22
0
def callback_worker(call):
    global language
    if call.data == "paper_free_1_1":
        with connection.cursor() as cursor:
            sql = "SELECT * FROM `current_game` WHERE first_user=%s"
            cursor.execute(sql, call.message.chat.id)
            result = cursor.fetchall()
        if result.__len__() == 0:
            with connection.cursor() as cursor:
                sql = "SELECT * FROM `current_game` WHERE second_user=%s"
                cursor.execute(sql, call.message.chat.id)
                result = cursor.fetchall()
            if result.__len__() == 0:
                bot.send_message(call.message.chat.id,
                                 text='Ви не берете участь у жодній грі',
                                 reply_markup=game_keyboard())
            else:
                if result[0]['first_user_check'] is None and result[0][
                        'second_user_check'] is None:
                    with connection.cursor() as cursor:
                        sql = "UPDATE `current_game` SET second_user_check= %s WHERE second_user=%s"
                        cursor.execute(sql, (1, result[0]['second_user']))
                    connection.commit()
                    bot.send_message(
                        call.message.chat.id,
                        text=
                        'Ваша відповідь врахована очікуйте ходу від суперника')
                elif result[0]['first_user_check'] is None:
                    bot.send_message(
                        call.message.chat.id,
                        text=
                        'Ви уже зробили свій вибір, очікуйте поки суперник зробить свій вибір.'
                    )
                else:
                    result[0]['second_user_check'] = 1
                    check_user_win(result[0], 'free_1_1')
        else:
            if result[0]['first_user_check'] is None and result[0][
                    'second_user_check'] is None:
                with connection.cursor() as cursor:
                    sql = "UPDATE `current_game` SET first_user_check= %s WHERE second_user=%s"
                    cursor.execute(sql, (1, result[0]['second_user']))
                connection.commit()
                bot.send_message(
                    call.message.chat.id,
                    text='Ваша відповідь врахована очікуйте ходу від суперника'
                )
            elif result[0]['second_user_check'] is None:
                bot.send_message(
                    call.message.chat.id,
                    text=
                    'Ви уже зробили свій вибір, очікуйте поки суперник зробить свій вибір.'
                )
            else:
                result[0]['first_user_check'] = 1
                check_user_win(result[0], 'free_1_1')
    elif call.data == 'scissors_free_1_1':
        with connection.cursor() as cursor:
            sql = "SELECT * FROM `current_game` WHERE first_user=%s"
            cursor.execute(sql, call.message.chat.id)
            result = cursor.fetchall()
        if result.__len__() == 0:
            with connection.cursor() as cursor:
                sql = "SELECT * FROM `current_game` WHERE second_user=%s"
                cursor.execute(sql, call.message.chat.id)
                result = cursor.fetchall()
            if result.__len__() == 0:
                bot.send_message(call.message.chat.id,
                                 text='Ви не берете участь у жодній грі',
                                 reply_markup=game_keyboard())
            else:
                if result[0]['first_user_check'] is None and result[0][
                        'second_user_check'] is None:
                    with connection.cursor() as cursor:
                        sql = "UPDATE `current_game` SET second_user_check= %s WHERE second_user=%s"
                        cursor.execute(sql, (2, result[0]['second_user']))
                    connection.commit()
                    bot.send_message(
                        call.message.chat.id,
                        text=
                        'Ваша відповідь врахована очікуйте ходу від суперника')
                elif result[0]['first_user_check'] is None:
                    bot.send_message(
                        call.message.chat.id,
                        text=
                        'Ви уже зробили свій вибір, очікуйте поки суперник зробить свій вибір.'
                    )
                else:
                    result[0]['second_user_check'] = 2
                    check_user_win(result[0], 'free_1_1')
        else:
            if result[0]['first_user_check'] is None and result[0][
                    'second_user_check'] is None:
                with connection.cursor() as cursor:
                    sql = "UPDATE `current_game` SET first_user_check= %s WHERE second_user=%s"
                    cursor.execute(sql, (2, result[0]['second_user']))
                connection.commit()
                bot.send_message(
                    call.message.chat.id,
                    text='Ваша відповідь врахована очікуйте ходу від суперника'
                )
            elif result[0]['second_user_check'] is None:
                bot.send_message(
                    call.message.chat.id,
                    text=
                    'Ви уже зробили свій вибір, очікуйте поки суперник зробить свій вибір.'
                )
            else:
                result[0]['first_user_check'] = 2
                check_user_win(result[0], 'free_1_1')

    elif call.data == 'stone_free_1_1':
        with connection.cursor() as cursor:
            sql = "SELECT * FROM `current_game` WHERE first_user=%s"
            cursor.execute(sql, call.message.chat.id)
            result = cursor.fetchall()
        if result.__len__() == 0:
            with connection.cursor() as cursor:
                sql = "SELECT * FROM `current_game` WHERE second_user=%s"
                cursor.execute(sql, call.message.chat.id)
                result = cursor.fetchall()
            if result.__len__() == 0:
                bot.send_message(call.message.chat.id,
                                 text='Ви не берете участь у жодній грі',
                                 reply_markup=game_keyboard())
            else:
                if result[0]['first_user_check'] is None and result[0][
                        'second_user_check'] is None:
                    with connection.cursor() as cursor:
                        sql = "UPDATE `current_game` SET second_user_check= %s WHERE second_user=%s"
                        cursor.execute(sql, (3, result[0]['second_user']))
                    connection.commit()
                elif result[0]['first_user_check'] is None:
                    bot.send_message(
                        call.message.chat.id,
                        text=
                        'Ви уже зробили свій вибір, очікуйте поки суперник зробить свій вибір.'
                    )
                else:
                    result[0]['second_user_check'] = 3
                    check_user_win(result[0], 'free_1_1')
        else:
            if result[0]['first_user_check'] is None and result[0][
                    'second_user_check'] is None:
                with connection.cursor() as cursor:
                    sql = "UPDATE `current_game` SET first_user_check= %s WHERE second_user=%s"
                    cursor.execute(sql, (3, result[0]['second_user']))
                connection.commit()
            elif result[0]['second_user_check'] is None:
                bot.send_message(
                    call.message.chat.id,
                    text=
                    'Ви уже зробили свій вибір, очікуйте поки суперник зробить свій вибір.'
                )
            else:
                result[0]['first_user_check'] = 3
                check_user_win(result[0], 'free_1_1')
Beispiel #23
0
def start(message):
    if message.text == '/start':
        with connection.cursor() as cursor:
            sql = "SELECT * FROM `users` WHERE `id`=%s"
            cursor.execute(sql, (message.from_user.id, ))
            result = cursor.fetchall()
        if result.__len__() == 0:
            bot.send_message(message.from_user.id,
                             "Оберіть мову:",
                             reply_markup=language_select_keyboard())
        else:
            bot.send_message(message.chat.id,
                             'Меню:',
                             reply_markup=main_menu())
    elif message.text == 'Грати':
        bot.send_message(message.from_user.id,
                         text='За що змагаємося: ',
                         reply_markup=game_keyboard())
    elif message.text == 'Профіль':
        try:
            with connection.cursor() as cursor:
                sql = "SELECT * FROM `users` WHERE `id`=%s"
                cursor.execute(sql, (message.from_user.id, ))
                result = cursor.fetchall()
        finally:
            name = result[0]['name']
            money = result[0]['money']
            reserved = result[0]['reserv_to_withdraw']
            text = f'Ім\'я: {name}\nГаманець: {money} тунгрики(need change) \nРезерв на виведення: {reserved}'
            bot.send_message(message.from_user.id,
                             text=text,
                             reply_markup=profile_keyboard())
    elif message.text == 'Правила':
        bot.send_message(message.from_user.id,
                         text=rules,
                         reply_markup=main_menu(),
                         parse_mode='HTML')
    elif message.text == "Зворотній зв'язок":
        bot.send_message(
            message.from_user.id,
            text='Введіть текст який хочете нам надіслати:',
        )
        bot.register_next_step_handler(message, callback=send_email)
Beispiel #24
0
def check_user_win(users, type):
    result = ''
    if users['first_user_check'] == 1 and users['second_user_check'] == 1:
        result = 'draw'
    elif users['first_user_check'] == 1 and users['second_user_check'] == 2:
        result = 'first_lose'
    elif users['first_user_check'] == 1 and users['second_user_check'] == 3:
        result = 'first_win'

    if users['first_user_check'] == 2 and users['second_user_check'] == 1:
        result = 'first_win'
    elif users['first_user_check'] == 2 and users['second_user_check'] == 2:
        result = 'draw'
    elif users['first_user_check'] == 2 and users['second_user_check'] == 3:
        result = 'first_lose'

    if users['first_user_check'] == 3 and users['second_user_check'] == 1:
        result = 'first_lose'
    elif users['first_user_check'] == 3 and users['second_user_check'] == 2:
        result = 'first_win'
    elif users['first_user_check'] == 3 and users['second_user_check'] == 3:
        result = 'draw'

    if result == 'draw':
        time.sleep(15)
        with connection.cursor() as cursor:
            sql = "DELETE FROM `current_game`  WHERE id=%s"
            cursor.execute(sql, users['id'])
        connection.commit()
        with connection.cursor() as cursor:
            sql = "INSERT INTO `current_game` (`first_user`, `second_user`, ) VALUES (%s, %s)"
            cursor.execute(sql, (users['first_user'], users['second_user']))
        connection.commit()
        bot.send_message(users['first_user'],
                         text='Нічия спробуйте знову...',
                         reply_markup=play_keyboard_free())
        bot.send_message(users['second_user'],
                         text='Нічия спробуйте знову...',
                         reply_markup=play_keyboard_free())
    if result == 'first_lose':
        time.sleep(15)
        bot.send_message(users['first_user'], text='Ви програли!')
        bot.send_message(users['second_user'], text='Ви виграли!')
        with connection.cursor() as cursor:
            sql = "DELETE FROM `current_game`  WHERE id=%s"
            cursor.execute(sql, users['id'])
        connection.commit()
    if result == 'first_win':
        time.sleep(15)
        bot.send_message(users['first_user'], text='Ви виграли!')
        bot.send_message(users['second_user'], text='Ви програли!')
        with connection.cursor() as cursor:
            sql = "DELETE FROM `current_game`  WHERE id=%s"
            cursor.execute(sql, users['id'])
        connection.commit()
Beispiel #25
0
def callback_worker(call):
    if call.data == 'turnir':
        bot.send_message(call.message.chat.id,
                         text='Оберіть: ',
                         reply_markup=turnir_keyboard())
    elif 'turnir16' in call.data:
        if call.data == 'turnir16':
            bot.send_message(call.message.chat.id,
                             text='Оберіть: ',
                             reply_markup=turnir16_keyboard())
        elif call.data == 'turnir1625':
            turnir(call, 16, 25)
        elif call.data == 'turnir1650':
            turnir(call, 16, 50)
        elif call.data == 'turnir16100':
            turnir(call, 16, 100)
    elif 'turnir32' in call.data:
        if call.data == 'turnir32':
            bot.send_message(call.message.chat.id,
                             text='Оберіть: ',
                             reply_markup=turnir32_keyboard())
        elif call.data == 'turnir3225':
            turnir(call, 32, 25)
        elif call.data == 'turnir3250':
            turnir(call, 32, 50)
        elif call.data == 'turnir32100':
            turnir(call, 32, 100)
    elif 'turnir64' in call.data:
        if call.data == 'turnir64':
            bot.send_message(call.message.chat.id,
                             text='Оберіть: ',
                             reply_markup=turnir64_keyboard())
        elif call.data == 'turnir6425':
            turnir(call, 64, 25)
        elif call.data == 'turnir6450':
            turnir(call, 64, 50)
        elif call.data == 'turnir64100':
            turnir(call, 64, 100)
    elif 'turnir256' in call.data:
        if call.data == 'turnir256':
            bot.send_message(call.message.chat.id,
                             text='Оберіть: ',
                             reply_markup=turnir256_keyboard())
        elif call.data == 'turnir25625':
            turnir(call, 256, 25)
        elif call.data == 'turnir25650':
            turnir(call, 256, 50)
        elif call.data == 'turnir256100':
            turnir(call, 256, 100)
    elif 'turnir1024' in call.data:
        if call.data == 'turnir1024':
            bot.send_message(call.message.chat.id,
                             text='Оберіть: ',
                             reply_markup=turnir1024_keyboard())
        elif call.data == 'turnir102425':
            turnir(call, 1024, 25)
        elif call.data == 'turnir102450':
            turnir(call, 1024, 50)
        elif call.data == 'turnir1024100':
            turnir(call, 1024, 100)