예제 #1
0
def handle_start(message):
    last_chat_id = str(message.chat.id)
    if dbr.get_players_condition(last_chat_id) == 'playing':

        if dbr.get_games_condition(
                dbr.get_game(last_chat_id).upper()) == 'wait':
            dbr.change_players_condition(last_chat_id, 'free')
            dbr.leave_game(last_chat_id)
            greet_bot.send_message(last_chat_id, 'Ты покинул игру')

        elif dbr.get_games_condition(
                dbr.get_game(last_chat_id).upper()) == 'going':
            dbr.change_players_condition(last_chat_id, 'free')
            dbr.set_target_to_user(dbr.get_user_killer(last_chat_id),
                                   dbr.get_user_target(last_chat_id))
            dbr.set_target_to_user(last_chat_id, '')
            dbr.leave_game(last_chat_id)
            greet_bot.send_message(last_chat_id, 'Ты покинул игру')

        markup = types.ReplyKeyboardMarkup()
        markup.row('создать игру')
        greet_bot.send_message(message.chat.id, "выбирай", reply_markup=markup)

    else:
        greet_bot.send_message(last_chat_id,
                               'Ты не можешь этого сделать, т.к. не играешь')
예제 #2
0
def handle_start(message):
    last_chat_id = str(message.chat.id)
    game = message.text.split()
    #print(game)
    game = game[len(game) - 1]
    #print(game)
    if dbr.get_players_condition(last_chat_id != 'playing'
                                 ) and dbr.get_games_condition(game) == 'wait':
        greet_bot.send_message(
            last_chat_id, 'Отлично сейчас я добавлю тебя в лобби: ' + game)
        dbr.join_game(last_chat_id, game)
        dbr.change_players_condition(last_chat_id, 'playing')

        for i in dbr.get_players(dbr.get_game(last_chat_id)):
            print(last_chat_id, i, dbr.get_nickname(last_chat_id))
            if last_chat_id != i:
                greet_bot.send_message(
                    i, 'К игре подключился: ' + dbr.get_nickname(last_chat_id))

        markup = types.ReplyKeyboardMarkup()
        markup.row('пригласить')
        markup.row('покинуть')
        greet_bot.send_message(last_chat_id, "Меню игры", reply_markup=markup)
    else:
        greet_bot.send_message(
            last_chat_id,
            'Ты не можешь этого сделать, т.к. находишься в другой игре. Доиграй или покинь её'
        )
예제 #3
0
def handle_start(message):
    last_chat_id = str(message.chat.id)
    if dbr.get_games_condition(dbr.get_game(last_chat_id).upper()) == 'wait':
        if len(dbr.get_players(dbr.get_game(last_chat_id))) > 2:

            config.get_victim(dbr.get_players(dbr.get_game(last_chat_id)))
            dbr.change_games_condition(dbr.get_game(last_chat_id), 'going')
            for i in dbr.get_players(dbr.get_game(last_chat_id)):
                greet_bot.send_message(
                    i, 'Игра начинается! Вот твоя жертва: ' +
                    dbr.get_nickname(dbr.get_user_target(i)))
                markup = types.ReplyKeyboardMarkup()
                markup.row('покинуть')
                greet_bot.send_message(i, "Удачи!", reply_markup=markup)
                greet_bot.send_message(
                    i,
                    'А этот код отдай своему убийце, если конечно тебя убили!')
                code = config.make_game()
                dbr.set_user_identifier(i, code)  # just generate a symbols
                greet_bot.send_message(i, code)
        else:
            greet_bot.send_message(
                last_chat_id,
                'Ты не можешь этого сделать, слишком мало игроков!')

    else:
        greet_bot.send_message(
            last_chat_id, 'Ты не можешь этого сделать, игра уже началась!')
예제 #4
0
def handle_start(message):
    last_chat_id = str(message.chat.id)
    if dbr.get_games_condition(dbr.get_game(last_chat_id).upper()) == 'going':
        code = message.text.split()[-1].upper()
        print(
            code,
            dbr.get_user_identifier(dbr.get_user_target(last_chat_id)).upper())
        print(dbr.get_user_target(last_chat_id))
        if dbr.get_user_identifier(
                dbr.get_user_target(last_chat_id)).upper() == code:
            died = dbr.get_user_target(last_chat_id)
            print(dbr.get_nickname(died))
            dbr.count_kill(last_chat_id)

            dbr.set_target_to_user(last_chat_id, dbr.get_user_target(died))

            print(dbr.get_user_killer(last_chat_id),
                  dbr.get_user_target(last_chat_id))
            if dbr.get_user_target(
                    dbr.get_user_killer(last_chat_id) == dbr.get_user_target(
                        last_chat_id)):

                if (dbr.get_amount_kills(last_chat_id) > dbr.get_amount_kills(
                        dbr.get_user_target(died))):
                    winner(last_chat_id)
                    kill(dbr.get_user_killer(last_chat_id))
                    kill(died)

                if (dbr.get_amount_kills(last_chat_id) == dbr.get_amount_kills(
                        dbr.get_user_target(died))):
                    winner(last_chat_id)
                    winner(dbr.get_user_killer(last_chat_id))
                    kill(died)

                if (dbr.get_amount_kills(last_chat_id) <
                        dbr.get_amount_kills(died)):
                    winner(dbr.get_user_killer(last_chat_id))
                    kill(last_chat_id)
                    kill(died)
            else:
                greet_bot.send_message(
                    last_chat_id,
                    'Отлично! Ты убил очередную жертву, вот тебе следущая: ' +
                    dbr.get_nickname(
                        dbr.get_user_target(died)))  # plus +1 kill
                # print(dbr.set_target_to_user(died, ''))
                # print(dbr.set_user_identifier(died, ''))
                # print(dbr.change_players_condition(died, 'free'))
                kill(died)
        else:
            greet_bot.send_message(last_chat_id,
                                   'Неверный код, проверь ещё раз')
    else:
        greet_bot.send_message(last_chat_id,
                               'Ты не можешь этого сейчас сделать')
예제 #5
0
def main():
    new_offset = None
    today = now.day
    hour = now.hour

    print('Запуск успешен')

    while True:
        try:
            greet_bot.get_updates(new_offset)
            last_update = greet_bot.get_last_update()
            last_update_id = last_update['update_id']
            last_chat_text = last_update['message']['text']
            last_chat_id = last_update['message']['chat']['id']
            last_chat_name = last_update['message']['chat']['first_name']
            dbr.registration(str(last_chat_id),
                             '@' + last_update['message']['chat']['username'])
            #print(last_update)
            ###########################################################################
            text = list(last_chat_text.lower().split())
            #print(text)
            ###########################################################################
            if text[0] == '/start':
                greet_bot.send_message(last_chat_id, '/Choose')

            if last_chat_name == 'Jonathan ⚡️' and text[0] == '/last_mess':
                last_mess(last_chat_id)
        ###########################################################################
            elif (text[0] == '/make_game'):
                try:
                    if dbr.get_players_condition(
                            str(last_chat_id) != 'playing'):  # what target?
                        name_of_game = make_game()
                        print(dbr.create_game(name_of_game))
                        print(dbr.change_games_condition(name_of_game, 'wait'))
                        print(dbr.join_game(str(last_chat_id), name_of_game))
                        print(
                            dbr.change_players_condition(
                                str(last_chat_id), 'playing'))
                        greet_bot.send_message(
                            last_chat_id,
                            'Отлично твоя игра создана, её уникальный номер: '
                            + name_of_game)
                    else:
                        greet_bot.send_message(
                            last_chat_id,
                            'Ты не можешь этого сделать, т.к. находишься в другой игре. Доиграй или покинь её'
                        )
                except:
                    greet_bot.send_message(
                        last_chat_id, 'Я такое не умею, может в следующий раз')
        ###########################################################################
            elif (
                    text[0] == '/join'
            ):  # проверить существует ли такое лобби и не играют ли уже там
                try:
                    game = text[len(text) - 1].upper()
                    if dbr.get_players_condition(
                            str(last_chat_id) != 'playing'
                    ) and dbr.get_games_condition(
                            game) == 'wait':  #what target?
                        greet_bot.send_message(
                            last_chat_id,
                            'Отлично сейчас я добавлю тебя в лобби: ' + game)
                        dbr.join_game(str(last_chat_id), game)
                        dbr.change_players_condition(str(last_chat_id),
                                                     'playing')  #what target?
                    else:
                        greet_bot.send_message(
                            last_chat_id,
                            'Ты не можешь этого сделать, т.к. находишься в другой игре. Доиграй или покинь её'
                        )
                    # else:
                    #     greet_bot.send_message(last_chat_id, 'Ты не можешь этого сделать, т.к. такой игры нет или она уже идёт(((')
                except:
                    greet_bot.send_message(
                        last_chat_id, 'Я такое не умею, может в следующий раз')

            elif text[0] == '/start_game' and dbr.get_games_condition(
                    dbr.get_game(str(last_chat_id)).upper()) == 'wait':
                #try:
                get_victim(dbr.get_players(dbr.get_game(str(last_chat_id))))
                dbr.change_games_condition(dbr.get_game(str(last_chat_id)),
                                           'going')
                for i in dbr.get_players(dbr.get_game(str(last_chat_id))):
                    print(i)
                    greet_bot.send_message(
                        i, 'Игра начинается! Вот твоя жертва: ' +
                        dbr.get_nickname(dbr.get_user_target(i)))
                    greet_bot.send_message(
                        i,
                        'А этот код отдай своему убийце, если конечно тебя убили!'
                    )
                    code = make_game()
                    dbr.set_user_identifier(i, code)  # just generate a symbols
                    greet_bot.send_message(i, code)

            elif text[0] == '/kill' and dbr.get_games_condition(
                    dbr.get_game(str(last_chat_id)).upper()) == 'going':
                code = text[len(text) - 1].upper()
                if dbr.get_user_identifier(
                        dbr.get_user_target(
                            str(last_chat_id))).upper() == code:

                    died = dbr.get_user_target(str(last_chat_id))

                    if str(last_chat_id) == dbr.get_user_target(died):
                        dbr.establish_winner(str(last_chat_id),
                                             dbr.get_game(str(last_chat_id)))
                        greet_bot.send_message(
                            str(last_chat_id),
                            'Поздравляю! Обыграв остальных участиков, ты ПОБЕДИЛ!'
                        )
                        dbr.set_target_to_user(str(last_chat_id), '')
                        dbr.set_user_identifier(str(last_chat_id), '')
                        dbr.change_players_condition(str(last_chat_id), 'free')
                        dbr.change_games_condition(
                            dbr.get_game(str(last_chat_id)), 'finish')
                        dbr.leave_game(str(last_chat_id))
                    else:
                        dbr.set_target_to_user(str(last_chat_id),
                                               dbr.get_user_target(died))
                        greet_bot.send_message(
                            str(last_chat_id),
                            'Отлично! Ты убил очередную жертву, вот тебе следущая: '
                            + dbr.get_nickname(
                                dbr.get_user_target(died)))  # plus +1 kill

                        dbr.set_target_to_user(died, '')
                        dbr.set_user_identifier(died, '')
                        dbr.change_players_condition(died, 'free')
                        greet_bot.send_message(
                            died,
                            'Тебя убили! Но ничего, в следующей игре тебе обязательно повезёт!'
                        )
                        greet_bot.send_message(died,
                                               'Можешь искать другую игру!')
                        dbr.leave_game(died)
                else:
                    greet_bot.send_message(str(last_chat_id),
                                           'Неверный код, проверь ещё раз')

            elif text[0] == '/leave' and dbr.get_players_condition(
                    str(last_chat_id)) == 'playing':

                if dbr.get_games_condition(
                        dbr.get_game(str(last_chat_id)).upper()) == 'wait':
                    dbr.change_players_condition(str(last_chat_id), 'free')
                    dbr.leave_game(str(last_chat_id))

                elif dbr.get_games_condition(
                        dbr.get_game(str(last_chat_id)).upper()
                ) == 'going':  # you need make function find_killer
                    dbr.change_players_condition(str(last_chat_id), 'free')
                    dbr.set_target_to_user(
                        dbr.get_user_killer(str(last_chat_id)),
                        dbr.get_user_target(str(last_chat_id)))
                    dbr.set_target_to_user(str(last_chat_id), '')
                    dbr.leave_game(str(last_chat_id))
                else:
                    greet_bot.send_message(
                        last_chat_id,
                        'Ты не можешь этого сделать, т.к. не играешь')

            elif text[0] == '/jesus':
                try:
                    f = open('Jesus.txt', 'r')
                    jesus = f.read()
                    greet_bot.send_message(last_chat_id, jesus)
                    f.close()
                except:
                    greet_bot.send_message(last_chat_id,
                                           'Ой ОЙ оЙ, за такое положен бан')
        except:
            print('Error')

    ###########################################################################

        file = open('lastmes.txt', 'a')
        file.write(last_chat_name + ' ' + last_chat_text + '\n')
        file.close()
        print(last_chat_name, last_chat_id,
              last_chat_text)  # View who is write && what
        #print(last_update['message'])
        new_offset = last_update_id + 1