Files
conjurer/conanjurer/conan-discord-bridge/bot/main.py
T
2026-06-04 19:13:50 +02:00

50 lines
1.2 KiB
Python

"""Punkt wejścia bota mostu Discord <-> Conan Exiles."""
from __future__ import annotations
import asyncio
import logging
import discord
from discord.ext import commands
from bot.core.config import Config
from bot.core.rcon import RconClient
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(levelname)s %(name)s: %(message)s",
)
log = logging.getLogger("main")
COGS = ["bot.cogs.from_conan", "bot.cogs.to_conan"]
class BridgeBot(commands.Bot):
def __init__(self, cfg: Config):
intents = discord.Intents.default()
intents.message_content = True # potrzebne do komend prefiksowych
super().__init__(command_prefix="!", intents=intents)
self.cfg = cfg
self.rcon = RconClient(cfg.rcon_host, cfg.rcon_port, cfg.rcon_password)
async def setup_hook(self):
for c in COGS:
await self.load_extension(c)
log.info("Załadowano cog: %s", c)
async def close(self):
await self.rcon.close()
await super().close()
async def on_ready(self):
log.info("Zalogowano jako %s (id=%s)", self.user, self.user.id)
def main():
cfg = Config.load()
bot = BridgeBot(cfg)
bot.run(cfg.token, log_handler=None)
if __name__ == "__main__":
main()