forked from Drakkar-Software/OctoBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitializer.py
58 lines (52 loc) · 2.46 KB
/
initializer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# This file is part of OctoBot (https://github.com/Drakkar-Software/OctoBot)
# Copyright (c) 2023 Drakkar-Software, All rights reserved.
#
# OctoBot is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# OctoBot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with OctoBot. If not, see <https://www.gnu.org/licenses/>.
import octobot_tentacles_manager.api as tentacles_manager_api
import octobot.constants as constants
import octobot_commons.databases as databases
import octobot_commons.logging as logging
import octobot_commons.errors as commons_errors
import octobot.databases_util as databases_util
class Initializer:
"""Initializer class:
- Initialize services, constants and tools
"""
def __init__(self, octobot):
self.octobot = octobot
async def create(self, init_bot_storage):
# initialize tentacle configuration
tentacles_config_path = self.octobot.get_startup_config(constants.CONFIG_KEY, dict_only=False).\
get_tentacles_config_path()
self.octobot.tentacles_setup_config = tentacles_manager_api.get_tentacles_setup_config(tentacles_config_path)
if init_bot_storage:
try:
# init bot storage
await databases.init_bot_storage(
self.octobot.bot_id,
databases_util.get_run_databases_identifier(
self.octobot.config,
self.octobot.tentacles_setup_config
),
True
)
except commons_errors.ConfigTradingError as err:
# already logged as error, don't display it twice
logging.get_logger(self.__class__.__name__).warning(f"Error when initializing bot storage: {err}")
except Exception as err:
logging.get_logger(self.__class__.__name__).exception(
err, True, f"Error when initializing bot storage: {err}"
)
# create OctoBot channel
await self.octobot.global_consumer.initialize()