-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (45 loc) · 1.51 KB
/
main.py
File metadata and controls
55 lines (45 loc) · 1.51 KB
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
import asyncio
import importlib.util
import sys
from pathlib import Path
import uvloop
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
from helpers.logger import LOGGER
from bot import ItsMrULPBot, start_bot
HANDLER_DIRS = [
Path(__file__).parent / "core",
Path(__file__).parent / "modules",
]
def load_handlers():
for directory in HANDLER_DIRS:
if not directory.is_dir():
continue
for path in sorted(directory.glob("*.py")):
if path.name == "__init__.py":
continue
module_name = f"{directory.name}.{path.stem}"
if module_name in sys.modules:
continue
try:
spec = importlib.util.spec_from_file_location(module_name, path)
if spec is None:
continue
module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module
spec.loader.exec_module(module)
except Exception as e:
LOGGER.error(f"Failed to load {module_name}: {e}")
async def run_bot():
await start_bot()
load_handlers()
me = await ItsMrULPBot.get_me()
LOGGER.info(f"Bot Successfully Started! 💥")
await ItsMrULPBot.run_until_disconnected()
if __name__ == "__main__":
try:
asyncio.run(run_bot())
except KeyboardInterrupt:
LOGGER.info("Bot stopped by user (KeyboardInterrupt)")
except Exception as e:
LOGGER.error(f"Fatal error: {e}")
sys.exit(1)