Посмотри, что не так с моим ботом и почему он не отвечает на сообщения. Код: 
import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType
from vk_api.keyboard import VkKeyboard, VkKeyboardColor
import random
import datetime
import io
import requests
import logging
import os
import json
from license_generator import ImageProcessor
import concurrent.futures
import time
from threading import Lock
import functools

logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

CONFIG_FILE = "config.json"
COMMANDS_FILE = "commands.json"


def load_config(config_path):
    try:
        with open(config_path, 'r', encoding='utf-8') as f:
            config = json.load(f)
            return config
    except FileNotFoundError:
        logging.error(f"Файл конфигурации не найден: {config_path}")
        return None
    except json.JSONDecodeError:
        logging.error(f"Ошибка декодирования JSON в файле: {config_path}")
        return None

def load_commands(commands_path):
    try:
        with open(commands_path, 'r', encoding='utf-8') as f:
            commands = json.load(f)
            return commands
    except FileNotFoundError:
        logging.error(f"Файл команд не найден: {commands_path}")
        return None
    except json.JSONDecodeError:
        logging.error(f"Ошибка декодирования JSON в файле: {commands_path}")
        return None


CONFIG = load_config(CONFIG_FILE)
if not CONFIG:
    exit(1)
COMMANDS = load_commands(COMMANDS_FILE)
if not COMMANDS:
    exit(1)

def retry(func, retries=3, delay=1):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        for attempt in range(retries):
            try:
                return func(*args, **kwargs)
            except (requests.exceptions.RequestException, vk_api.exceptions.ApiError) as e:
                logging.error(f"Ошибка в {func.__name__}, попытка {attempt + 1}: {e}. Повтор через {delay} секунд.")
                if attempt < retries - 1:
                   time.sleep(delay)
        logging.error(f"Сбой в {func.__name__} после {retries} попыток.")
        return None
    return wrapper

class VkBot:
    def get_group_name(self):
      try:
        group_info = self.vk.groups.getById(group_id=self.config["group_id"], fields='screen_name')
        return group_info[0]['screen_name']
      except vk_api.exceptions.ApiError as e:
        logging.error(f"Ошибка при получении имени группы: {e}")
        return None
    
    def __init__(self, config, image_processor, num_threads=5):
        self.config = config
        self.image_processor = image_processor
        self.vk_session = vk_api.VkApi(token=self.config["tokens"]["group"])
        self.vk = self.vk_session.get_api()
        self.vk_session_user = vk_api.VkApi(token=self.config["tokens"]["user"])
        self.vk_user = self.vk_session_user.get_api()
        self.longpoll = VkLongPoll(self.vk_session)
        self.executor = concurrent.futures.ThreadPoolExecutor(max_workers=num_threads)
        self.user_processing = {}
        self.cache_lock = Lock()
        self.user_state = {}

    def create_keyboard(self, keyboard_name):
        if keyboard_name not in COMMANDS["keyboards"]:
            logging.warning(f"Клавиатура {keyboard_name} не найдена.")
            return None
        keyboard = VkKeyboard(one_time=False)
        buttons = sorted(COMMANDS["keyboards"][keyboard_name], key=lambda x: x.get("layer", 1))
        current_layer = 1
        for button in buttons:
           if button.get("layer", 1) != current_layer:
              keyboard.add_line()
              current_layer = button.get("layer", 1)
           keyboard.add_button(button["text"], color=button["color"])
        return keyboard.get_keyboard()
    
    def load_all_albums(self):
       logging.info("Загрузка списка альбомов...")
       owner_id = self.config["group_id"]
       try:
          for album_name, album_id in self.config["albums_urls"].items():
             logging.info(f"Получение фотографий из альбома: {album_name} ({album_id})")
             try:
                photos = self.vk_user.photos.get(owner_id=owner_id, album_id=album_id, count=1)['items']
                if not photos:
                   logging.warning(f"В альбоме {album_name} ({album_id}) нет фотографий или доступ к альбому закрыт.")
             except vk_api.exceptions.ApiError as e:
                logging.error(f"Ошибка при получении альбома {album_name}: {e}")

       except Exception as e:
          logging.error(f"Ошибка при загрузке списка альбомов: {e}")
    
    @retry
    def get_random_photo(self, album_id):
        owner_id = self.config["group_id"]
        logging.info(f"Запрос фото. Owner ID: {owner_id}, Album ID: {album_id}")
        photos = self.vk_user.photos.get(owner_id=owner_id, album_id=album_id, count=100)['items']
        if not photos:
            logging.warning(f"В альбоме {album_id} нет фотографий или доступ к альбому закрыт.")
            return None
        logging.info("Фото успешно получены.")
        return random.choice(photos)['sizes'][-1]['url']

    @retry
    def check_is_don(self, user_id):
        return self.vk.groups.isMember(group_id=self.config["donate_group_id"], user_id=user_id)

    @retry
    def send_vk_message(self, user_id, message, keyboard=None):
        try:
            self.vk.messages.send(peer_id=user_id, random_id=random.randint(0, 2 ** 20), message=message)
            if keyboard:
              logging.info(f"Клавиатура {keyboard} отправлена")
        except vk_api.exceptions.ApiError as e:
            logging.error(f"Ошибка при отправке сообщения: {e}")
        except Exception as e:
            logging.error(f"Неизвестная ошибка при отправке сообщения: {e}")

    @retry
    def send_image_vk(self, image, user_id):
            image_bytes = io.BytesIO()
            image.save(image_bytes, format="PNG")
            image_bytes.seek(0)
            upload_url = self.vk.photos.getMessagesUploadServer(peer_id=user_id)["upload_url"]
            upload_response = requests.post(upload_url, files={'photo': ('image.png', image_bytes)}).json()
            if "photo" not in upload_response:
                logging.error(f"Ошибка загрузки: {upload_response}")
                return
            photo = self.vk.photos.saveMessagesPhoto(photo=upload_response['photo'], server=upload_response['server'],
                                                    hash=upload_response['hash'])[0]
            self.vk.messages.send(peer_id=user_id, random_id=random.randint(0, 2 ** 20),
                                  attachment=f"photo{photo['owner_id']}_{photo['id']}")
            logging.info(f"Изображение отправлено: {user_id}.")
    
    def _get_license_data(self, user_id, selected_character, album_id) -> tuple:
        is_don = self.check_is_don(user_id)
        if is_don is None:
            raise ValueError("Не удалось проверить статус дона.")
        
        photo_url = self.get_random_photo(album_id)
        if not photo_url:
            raise ValueError("Не удалось получить фото")
    
        user_info = self.vk.users.get(user_ids=user_id)[0]
        user_name = f"{user_info.get('first_name', 'Noname')} {user_info.get('last_name', '')}"
        
        today = datetime.date.today()
        date_start = today.strftime("%d.%m.%Y")
        date_end = "Бессрочно" if is_don else (today + datetime.timedelta(days=30)).strftime("%d.%m.%Y")
        license_id = f"{'D' if is_don else 'F'}-{random.randint(10000000, 99999999)}"
        
        group_name = self.get_group_name()
        if group_name is None:
            raise ValueError("Не удалось получить имя группы")
        return user_name, date_start, date_end, license_id, photo_url, is_don, group_name
    
    def _create_qr_code(self, user_id: int, is_don: bool):
        if is_don:
            return self.image_processor.generate_qr_code(f"https://vk.com/id{user_id}")
        return self.image_processor.generate_qr_code(self.config["qr_default_url"])

    def _send_license_image(self, user_id: int, image):
        if image:
            self.send_image_vk(image, user_id)
            with self.cache_lock:
                self.user_processing[user_id] = False
        else:
            self.send_vk_message(user_id, "Ошибка создания лицензии")
            with self.cache_lock:
               self.user_processing[user_id] = False

    def process_license_async(self, user_id, selected_character, album_id):
        with self.cache_lock:
            if self.user_processing.get(user_id, False):
                self.send_vk_message(user_id, "Пожалуйста, дождитесь завершения предыдущего запроса.")
                return
            self.user_processing[user_id] = True
        self.executor.submit(self.process_license, user_id, selected_character, album_id)
    
    def process_license(self, user_id, selected_character, album_id):
        try:
             user_name, date_start, date_end, license_id, photo_url, is_don, group_name = self._get_license_data(user_id, selected_character, album_id)
            
             def download_image_with_retry(url, retries=3, delay=1):
                 for attempt in range(retries):
                    try:
                        background = self.image_processor.download_image(url)
                        if background:
                            return background
                    except requests.exceptions.RequestException as e:
                         logging.error(f"Ошибка при загрузке фото, попытка {attempt + 1}: {e}")
                         if attempt < retries - 1:
                           time.sleep(delay)
                    except Exception as e:
                         logging.error(f"Неизвестная ошибка при загрузке фото, попытка {attempt + 1}: {e}")
                         if attempt < retries - 1:
                           time.sleep(delay)
                 return None
            
             background = download_image_with_retry(photo_url)

             if not background:
                self.send_vk_message(user_id, "Не удалось загрузить фон")
                with self.cache_lock:
                    self.user_processing[user_id] = False
                return
             user_data = {
                'user_name': user_name,
                'date_start': date_start,
                'date_end': date_end,
                'license_id': license_id,
                'license_text': f"ЛИЦЕНЗИЯ НА {selected_character.upper()}",
                'group_name': group_name  # Добавляем короткое имя группы
            }
             qr_code = self._create_qr_code(user_id, is_don)

             def callback(license_image):
                self._send_license_image(user_id, license_image)

             self.image_processor.process_license_async(user_id, background, user_data, qr_code, callback)

        except ValueError as e:
            self.send_vk_message(user_id, str(e))
            logging.error(f"Ошибка обработки: {e}")
            with self.cache_lock:
                self.user_processing[user_id] = False
        except Exception as e:
            self.send_vk_message(user_id, f"Ошибка: {e}")
            logging.error(f"Ошибка обработки: {e}")
            with self.cache_lock:
                self.user_processing[user_id] = False

    def shutdown(self):
        logging.info("Завершение работы ботом...")
        self.executor.shutdown(wait=True)
        logging.info("Все потоки завершены.")

    def handle_command(self, user_id, user_text):
        state = self.user_state.get(user_id, {"menu": "main"})
        logging.info(f"Команда: {user_text}, состояние: {state}")
        if user_text == "назад":
            if state["menu"] == "character":
                self.user_state[user_id] = {"menu": "main"}
                self.send_vk_message(user_id, "Что вы хотите сделать?", keyboard=self.create_keyboard("main_menu"))
            elif state["menu"] == "albums":
                self.user_state[user_id] = {"menu": "character"}
                self.send_vk_message(user_id, "Выберите персонажа для лицензии:", keyboard=self.create_keyboard("character_selection"))
            elif state["menu"] == "license_options":
                  character_name = state.get("character")
                  if character_name:
                     self.user_state[user_id] = {"menu": "albums", "character": character_name}
                     character_data = COMMANDS["characters"].get(character_name)
                     if character_data:
                       keyboard_name = character_data.get("albums_keyboard")
                       keyboard = self.create_keyboard(keyboard_name)
                       self.send_vk_message(user_id, f"Выберите альбом для персонажа {character_data.get('text')}", keyboard=keyboard)
                  else:
                    self.user_state[user_id] = {"menu": "main"}
                    self.send_vk_message(user_id, "Что вы хотите сделать?", keyboard=self.create_keyboard("main_menu"))
            else:
                self.user_state[user_id] = {"menu": "main"}
                self.send_vk_message(user_id, "Что вы хотите сделать?", keyboard=self.create_keyboard("main_menu"))

        elif user_text == "меню":
            self.user_state[user_id] = {"menu": "main"}
            self.send_vk_message(user_id, "Что вы хотите сделать?", keyboard=self.create_keyboard("main_menu"))
        else:
            command = COMMANDS["commands"].get(user_text, COMMANDS["commands"]["default"])
            logging.info(f"Команда: {user_text}, состояние: {state}, command: {command}")
            if command is None:
                logging.error(f"Команда {user_text} не найдена в commands.json!")
                self.send_vk_message(user_id, "Неизвестная команда")
                self.user_state[user_id] = {"menu": "main"}
                return
            if "response" in command:
                logging.info(f"Найдена команда с ответом. {command}")
                keyboard = self.create_keyboard(command.get("keyboard"))
                logging.info(f"Клавиатура: {keyboard} для команды: {command}")
                self.send_vk_message(user_id, command["response"], keyboard=keyboard)
                if user_text == "лицензия":
                  logging.info(f"Переход в состояние 'character'.")
                  self.user_state[user_id] = {"menu": "character"}
            elif state["menu"] == "character":
                character_data = COMMANDS["characters"].get(user_text)
                if character_data:
                    albums_keyboard = character_data.get("albums_keyboard")
                    if albums_keyboard:
                      self.user_state[user_id] = {"menu": "albums", "character": user_text}
                      keyboard = self.create_keyboard(albums_keyboard)
                      self.send_vk_message(user_id, f"Выберите альбом для персонажа {character_data.get('text')}", keyboard=keyboard)
                    else:
                       if user_text == "случайная лицензия":
                           characters = list(COMMANDS["characters"].keys())
                           if "случайная лицензия" in characters:
                              characters.remove("случайная лицензия")
                           random_character = random.choice(characters)
                           albums_keyboard = COMMANDS["characters"].get(random_character).get("albums_keyboard")
                           if albums_keyboard:
                               albums = COMMANDS["albums"].get(albums_keyboard)
                               if albums:
                                 random_album = random.choice(albums)
                                 self.process_license_async(user_id, random_character, random_album["album_id"])
                           self.user_state[user_id] = {"menu": "license_options", "character": random_character}
                else:
                   self.send_vk_message(user_id, "Неизвестная команда", keyboard = self.create_keyboard("back_and_menu"))
            elif state["menu"] == "albums":
                  character_name = state.get("character")
                  albums_keyboard = COMMANDS["characters"].get(character_name).get("albums_keyboard")
                  if albums_keyboard:
                     albums = COMMANDS["albums"].get(albums_keyboard)
                     for album in albums:
                         if album.get("text") == user_text:
                            self.process_license_async(user_id, character_name, album.get("album_id"))
                            self.user_state[user_id] = {"menu": "license_options", "character": character_name, "album": album.get("text")}
                            self.send_vk_message(user_id, "Лицензия создана", keyboard=self.create_keyboard("back_and_menu"))
                            return
                     self.send_vk_message(user_id, "Неизвестная команда", keyboard = self.create_keyboard("back_and_menu"))
            elif state["menu"] == "license_options":
                 self.send_vk_message(user_id, "Лицензия создана", keyboard=self.create_keyboard("back_and_menu"))
            else:
               logging.info(f"Вызов дефолтной команды.")
               self.send_vk_message(user_id, "Неизвестная команда")
               self.user_state[user_id] = {"menu": "main"}


    def run(self):
        logging.info("Бот запущен. Ожидание сообщений...")
        self.load_all_albums()
        while True:
            try:
                for event in self.longpoll.listen():
                    if event.type == VkEventType.MESSAGE_NEW and event.to_me:
                        user_id, user_text = event.user_id, event.text.lower()
                        logging.info(f"Новое сообщение от {user_id}: {user_text}")
                        self.handle_command(user_id, user_text)

            except requests.exceptions.RequestException as e:
                logging.error(f"Проблема с сетью: {e}. Переподключение через 5 секунд...")
                time.sleep(5)
            except vk_api.exceptions.ApiError as e:
                logging.error(f"Проблема с API VK: {e}. Переподключение через 5 секунд...")
                time.sleep(5)
            except Exception as e:
                 logging.error(f"Неизвестная ошибка в основном цикле: {e}. Переподключение через 5 секунд...")
                 time.sleep(5)
            finally:
                pass

if __name__ == "__main__":
    image_processor = ImageProcessor(CONFIG)
    num_threads = 8
    bot = VkBot(CONFIG, image_processor, num_threads=num_threads)
    bot.run()
Логи: ```
2025-01-08 11:10:29,796 - INFO - Новое сообщение от 389769778: начать
2025-01-08 11:10:29,796 - INFO - Команда: начать, состояние: {'menu': 'main'}
2025-01-08 11:10:29,796 - ERROR - Неизвестная ошибка в основном цикле: 'default'. Переподключение через 5 секунд...

```