Exemple #1
0
 def pop_info(self, call):
     try:
         bot_methods.answer_callback_query(call=call,
                                           text=self.info_string().translate(self.unit.controler.lang))
     except bot_methods.telebot.apihelper.ApiException:
         bot_methods.send_message(call.message.chat.id,
                                  message=self.info_string().translate(self.unit.controler.lang))
Exemple #2
0
 def activate(self):
     bot_methods.answer_callback_query(
         call=self.call,
         text=self.unit.info_string(
             lang=self.unit.controller.lang).translate(
                 self.unit.controller.lang),
         alert=True)
Exemple #3
0
def action(call):
    if call.data == 'test':
        bot_methods.answer_callback_query(call, '89296052405', alert=True)
    try:
        call_handler.handle(call)
    except Exception as e:
        import traceback
        bot_methods.err(traceback.format_exc())
Exemple #4
0
 def move_permission(self, movement, call):
     if not self.open:
         bot_methods.answer_callback_query(
             call,
             'Вы не можете двигаться дальше, пока не откроете клетку.',
             alert=True)
         return False
     return True
Exemple #5
0
 def act(self):
     self.current_war.add_attack_lobby(self.chat.chat_id, self.target_chat.chat_id)
     if self.current_war.stage == 'siege':
         self.chat.add_resources(-self.chat.get_attack_price(self.target_chat))
         answer_callback_query(self.call,
                               'Вы платите {} ресурсов за атаку.'.format(self.chat.get_attack_price(self.target_chat)),
                               alert=False)
     self.chat.attack_chat(self.call, self.target_chat)
Exemple #6
0
 def handle(call):
     call_data = call.data.split('_')
     user_id = call.from_user.id
     chat = get_chat(call_data[1])
     action = call_data[2]
     if not chat.is_admin(user_id):
         answer_callback_query(call, 'Вы не админ в этом чате!')
         return False
     chat_action_dict[action](chat, user_id, call).func()
Exemple #7
0
    def handle(call):
        call_data = call.data.split('_')
        action = call_data[2]
        try:
            lobby = dynamic_dicts.lobby_list[call_data[1]]
        except:
            return False

        if action == 'startlobby':
            dynamic_dicts.lobby_list[call_data[1]].start()

        elif action == 'equipment':
            user_id = call.from_user.id
            unit_dict = lobby[user_id]['unit_dict']
            user = get_user(call.from_user.id)
            chat = get_chat(lobby.chat_id)
            item_type = call_data[3]
            item_name = call_data[-1]
            item = standart_actions.object_dict[item_name]() if item_name not in ['reset', 'ready'] else None
            if item_name == 'reset':
                if item_type == 'armor':
                    for armor in unit_dict['armor']:
                        chat.delete_used_item(armor['name'])
                    unit_dict['armor'] = []
                elif item_type == 'item':
                    for item_unit in unit_dict['inventory'].values():
                        chat.delete_used_item(item_unit[0]['name'], value=item_unit[1])
                    unit_dict['inventory'] = {}
                user.send_equipment_choice(call_data[1], chat.chat_id, item_type, message_id=call.message.message_id)
            elif item_name == 'ready':
                lobby[user_id]['equipment_choice'].pop()
                lobby.run_next_step(user_id, message_id=call.message.message_id)

            elif item_name not in chat.get_free_armory():
                bot_methods.answer_callback_query(call, 'Этого предмета уже нет на складе')
                user.send_equipment_choice(call_data[1], chat.chat_id, item_type, message_id=call.message.message_id)
            elif not item.try_placement(unit_dict):
                bot_methods.answer_callback_query(call, 'Вы не можете это экипировать.')

            elif item_type == 'weapon':
                chat.use_item(item_name)
                unit_dict['weapon'] = item.to_dict()
                lobby[user_id]['equipment_choice'].pop()
                lobby.run_next_step(user_id, message_id=call.message.message_id)
            elif item_type == 'armor':
                chat.use_item(item_name)
                unit_dict['armor'].append(item.to_dict())
                user.send_equipment_choice(call_data[1], chat.chat_id, item_type, message_id=call.message.message_id)
            elif item_type == 'item':
                chat.use_item(item_name)
                test = list(k for k, v in unit_dict['inventory'].items() if v[0]['name'] == item['name'])
                if test:
                    unit_dict['inventory'][test[0]][1] += 1
                else:
                    unit_dict['inventory'][engine.rand_id()] = [item.to_dict(), 1]
                user.send_equipment_choice(call_data[1], chat.chat_id, item_type, message_id=call.message.message_id)
Exemple #8
0
 def move_permission(self, movement, call):
     if self.entrance_loc is None:
         self.entrance_loc = movement.start_location
         return True
     elif movement.end_location != self.entrance_loc and movement.end_location != self:
         if not any('torch' in member.inventory.items()
                    for member in movement.party.members):
             bot_methods.answer_callback_query(
                 call, 'У вас нет факела, чтобы пройти дальше', alert=True)
             return False
     return True
Exemple #9
0
 def func(self):
     available_result = self.available()
     if not available_result[0]:
         return self.refuse(available_result[1])
     if self.acting:
         if available_result[1] is not True:
             answer_callback_query(self.call, available_result[1], alert=False)
         self.act()
         if self.return_to_parent:
             self.parent_menu(self.menu_object, self.user_id, call=self.call).send_page()
     else:
         self.send_page()
Exemple #10
0
    def act(self):
        available_abilities = self.user.get_possible_abilities_amount()
        if available_abilities:
            if not any(self.ability.name == ability['name'] for ability in self.user.get_abilities()):
                self.user.add_ability(self.ability)
                answer_callback_query(self.call, 'Вы приобретаете способность "{}"'.format(self.ability.name_lang_tuple().translate('rus')))
            else:
                answer_callback_query(self.call, 'У вас уже есть эта способность!'.format(self.ability.name_lang_tuple().translate('rus')))

        else:
            answer_callback_query(self.call, 'что-то пошло не так')
Exemple #11
0
    def act(self):
        available_abilities = self.user.get_possible_abilities_amount()
        if available_abilities:
            if self.ability.name not in [
                    ab.name for ab in get_possible_abilities(
                        self.user.experience, self.user.get_abilities())
            ]:
                answer_callback_query(
                    self.call, 'Вы не можете взять способность "{}"'.format(
                        self.ability.name_lang_tuple().translate('rus')))
            elif not any(self.ability.name == ability['name']
                         for ability in self.user.get_abilities()):
                self.user.add_ability(self.ability)
                answer_callback_query(
                    self.call, 'Вы приобретаете способность "{}"'.format(
                        self.ability.name_lang_tuple().translate('rus')))
            else:
                answer_callback_query(
                    self.call, 'У вас уже есть эта способность!'.format(
                        self.ability.name_lang_tuple().translate('rus')))
            UserMainMenu(self.user, self.user_id, call=self.call).send_page()

        else:
            answer_callback_query(self.call, 'что-то пошло не так')
Exemple #12
0
 def ask_move(self, location, call):
     if location == self.current_location:
         self.member_dict[call.from_user.id].member_menu_start()
     elif not self.current_location.is_close(location):
         bot_methods.answer_callback_query(call,
                                           'Слишком далеко.',
                                           alert=False)
     elif call.from_user.id != self.leader.chat_id:
         bot_methods.answer_callback_query(call,
                                           'Вы не лидер группы!',
                                           alert=False)
     elif self.occupied():
         bot_methods.answer_callback_query(call,
                                           'Ваша группа занята!',
                                           alert=False)
     else:
         return True
     return False
Exemple #13
0
 def refuse(self, refuse_text):
     answer_callback_query(self.call, refuse_text)
Exemple #14
0
 def move_permission(self, movement, call):
     bot_methods.answer_callback_query(call, 'Вы не можете здесь пройти.', alert=False)
     return self.available()
Exemple #15
0
 def answer_callback_query(call, text, alert=True):
     bot_methods.answer_callback_query(call, text, alert=alert)
Exemple #16
0
 def pop_info(self, call):
     bot_methods.answer_callback_query(call=call,
                                       text=localization.LangTuple(
                                           self.table_row,
                                           'info').translate(
                                               self.unit.controller.lang))
Exemple #17
0
 def alert(self, text, call, alert=False):
     bot_methods.answer_callback_query(call, text, alert=alert)