-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
50 lines (38 loc) · 1.56 KB
/
main.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
import asyncio
import importlib
import json
import os
from typing import Type
from dotenv import load_dotenv
from threading import Thread
from Base import BaseInterface, Interface
from interfaces.Discord import DiscordInterface
from interfaces.Telegram import TelegramInterface
load_dotenv()
DIRECTORY = "interfaces"
def load_interfaces(base_interface: BaseInterface, directory=DIRECTORY, list="list.json"):
results = []
# Проходим по всем папкам в указанной директории
if list in os.listdir(directory):
list_of_interfaces = json.load(open(os.path.join(os.getcwd(), directory, list)))
for i in list_of_interfaces:
module_name = f"{directory}.{i}"
# try:
# Импортируем модуль
module = importlib.import_module(module_name)
# Проверяем наличие подкласса BaseInterface
if hasattr(module, "get"):
interface: Type = module.get()
if issubclass(interface, Interface):
obj = interface(base_interface)
results.append(obj)
# except ImportError as e:
# print(f"Ошибка при импорте модуля: {module_name}: {repr(e)}")
return results
if __name__ == '__main__':
# Запуск ядра
base = BaseInterface()
# print(interfaces)
discord = Thread(target=lambda: DiscordInterface(base).start(asyncio.new_event_loop()))
discord.start()
TelegramInterface(base).start(None)