Discord/main.py

52 lines
1.2 KiB
Python
Raw Normal View History

2023-05-02 16:46:15 +03:00
import logging
import sys
from logging import Logger
2024-12-17 23:14:06 +02:00
from pathlib import Path
2023-05-02 16:46:15 +03:00
2024-12-17 23:14:06 +02:00
from discord import LoginFailure, Intents
2024-12-16 00:36:48 +02:00
from libbot.sync import config_get as sync_config_get
2023-05-02 16:46:15 +03:00
2024-12-17 23:14:06 +02:00
from classes.holo_bot import HoloBot
2024-12-16 21:59:10 +02:00
from modules.scheduler import scheduler
2023-05-02 16:46:15 +03:00
logging.basicConfig(
level=logging.INFO,
format="%(name)s.%(funcName)s | %(levelname)s | %(message)s",
datefmt="[%X]",
)
logger: Logger = logging.getLogger(__name__)
2023-05-02 16:46:15 +03:00
try:
2023-05-04 17:14:33 +03:00
import uvloop # type: ignore
2023-05-02 16:46:15 +03:00
uvloop.install()
except ImportError:
pass
2024-12-17 23:14:06 +02:00
def main() -> None:
if not Path("config.json").exists():
logger.error(
"Config file is missing: Make sure the configuration file 'config.json' is in place."
2023-05-06 20:06:04 +03:00
)
2024-12-17 23:14:06 +02:00
sys.exit()
2023-05-04 17:14:33 +03:00
2024-12-17 23:14:06 +02:00
intents: Intents = Intents().all()
client: HoloBot = HoloBot(intents=intents, scheduler=scheduler)
2023-05-02 16:46:15 +03:00
2024-06-23 13:05:03 +03:00
client.load_extension("cogs")
2023-05-04 17:09:47 +03:00
2023-05-02 16:46:15 +03:00
try:
2024-12-16 00:36:48 +02:00
client.run(sync_config_get("bot_token", "bot"))
2024-12-17 23:14:06 +02:00
except LoginFailure as exc:
logger.error("Provided bot token is invalid: %s", exc)
2023-05-02 16:46:15 +03:00
except KeyboardInterrupt:
2024-12-17 23:14:06 +02:00
logger.info("KeyboardInterrupt received: Shutting down gracefully.")
finally:
sys.exit()
2023-05-02 16:46:15 +03:00
2023-05-04 17:14:33 +03:00
2023-05-02 16:46:15 +03:00
if __name__ == "__main__":
2023-05-04 17:14:33 +03:00
main()