mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-17 23:32:10 +00:00
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
"""Cog: relacja Conan -> Discord. Uruchamia obserwator logu i wrzuca zdarzenia
|
|
na właściwe kanały."""
|
|
from __future__ import annotations
|
|
import asyncio
|
|
import logging
|
|
|
|
import discord
|
|
from discord.ext import commands
|
|
|
|
from bot.core.logwatch import watch, Event
|
|
|
|
log = logging.getLogger("from_conan")
|
|
|
|
|
|
class FromConan(commands.Cog):
|
|
def __init__(self, bot: commands.Bot):
|
|
self.bot = bot
|
|
self._task: asyncio.Task | None = None
|
|
|
|
async def cog_load(self):
|
|
self._task = asyncio.create_task(self._run())
|
|
|
|
async def cog_unload(self):
|
|
if self._task:
|
|
self._task.cancel()
|
|
|
|
async def _run(self):
|
|
await self.bot.wait_until_ready()
|
|
cfg = self.bot.cfg
|
|
chat_ch = self.bot.get_channel(cfg.chan_chat)
|
|
evt_ch = self.bot.get_channel(cfg.chan_events)
|
|
|
|
async def on_event(e: Event):
|
|
target = chat_ch if e.kind == "chat" else evt_ch
|
|
if target is not None:
|
|
# allowed_mentions: nie pinguj nikogo treścią z gry
|
|
await target.send(e.text, allowed_mentions=discord.AllowedMentions.none())
|
|
|
|
log.info("Start obserwacji logu (tryb=%s)", cfg.log_mode)
|
|
await watch(cfg, on_event)
|
|
|
|
|
|
async def setup(bot: commands.Bot):
|
|
await bot.add_cog(FromConan(bot))
|