-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
56 lines (44 loc) · 1.37 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
51
52
53
54
55
56
#!/usr/bin/env python3
# Import bot framework
from avilla.core import Avilla
# Import external utilities
from creart import create
from graia.saya import Saya
# Import internal utilities
from utils import avilla as _extra # noqa: F401
from utils.graia.service import add_available_services
from utils.config import load_config
from utils.logger import logger
from utils.module import get_modules
# TODO: Web (FastAPI)
# bot_config.server.enable = False
def main():
"""Main function."""
# Init
saya = create(Saya)
app = Avilla()
bot_config = load_config()
# Configure
if bot_config.dry_run:
# For development
from avilla.console.protocol import ConsoleProtocol
app.apply_protocols(ConsoleProtocol())
else:
for protocol_config in bot_config.protocols:
protocol_config.configure(app)
add_available_services(app.launch_manager)
# TODO: Web
# Load modules
with saya.module_context():
if (modules := bot_config.modules) is None:
logger.info('Automatically loading modules...')
modules = get_modules()
for module_name in modules:
try:
saya.require(module_name)
except ImportError as e:
logger.error(f'Failed to load {module_name}: {e.msg}')
# Launch
app.launch()
if __name__ == '__main__':
main()