from bot.action.core.action import Update, Action
from bot.api.api import Api
from bot.api.telegram import TelegramBotApi
from bot.logger.admin_logger import AdminLogger
from bot.multithreading.scheduler import SchedulerApi
from bot.storage import Config, Cache
from bot.storage import State


CONFIG_DIR = "config"
STATE_DIR = "state"


class Bot:
    def __init__(self):
        self.config = Config(CONFIG_DIR)
        self.state = State(STATE_DIR)
        self.cache = Cache()
        debug = self.config.is_debug_enabled()
        telegram_api = TelegramBotApi(self.config.auth_token, debug)
        self.api = Api(telegram_api, self.state)
        self.logger = AdminLogger(self.api, self.config.admin_chat_id, debug)
        self.scheduler = SchedulerApi(self.logger.work_error)
        self.scheduler.setup()
        self.api.enable_async(self.scheduler)
        self.cache.bot_info = self.api.getMe()
        self.action = Action()

    def set_action(self, action: Action):
        action.setup(self.api, self.config, self.state, self.cache, self.scheduler)
        self.action = action

    def run(self):
        self.logger.info("Started")
        try:
            self.main_loop()
        except KeyboardInterrupt:
            self.logger.info("KeyboardInterrupt")
        except SystemExit as e:
            self.logger.info("SystemExit: " + str(e))
            raise e
        except BaseException as e:
            self.logger.error(e, "Fatal error")
            raise e
        finally:
            self.shutdown()

    def main_loop(self):
        for update in self.get_updates(self.api.get_pending_updates):
            self.process_update(update, is_pending=True)
        while True:
            for update in self.get_updates(self.api.get_updates):
                self.process_update(update)

    def get_updates(self, get_updates_func):
        try:
            return get_updates_func()
        except Exception as e:
            self.logger.error(e, "get_updates")

    def process_update(self, update, is_pending=False):
        try:
            self.action.process(Update(update, is_pending))
        except Exception as e:
            self.logger.error(e, "process_update")

    def shutdown(self):
        self.scheduler.shutdown()
        self.logger.info("Finished")

@@ -32,22 +32,56 @@
 ort 
-Update, Action
+Action%0Afrom bot.action.core.update import Update
 %0Afro
@@ -1698,25 +1698,8 @@
 date
-, is_pending=True
 )%0A  
@@ -2042,25 +2042,15 @@
 date
-, is_pending=Fals
+: Updat
 e):%0A
@@ -2098,34 +2098,14 @@
 ess(
-Update(update, is_pending)
+update
 )%0A  

Update Bot to pass directly the Update received from get_updates to process it