2023-07-27 22:55:55 +02:00

35 lines
1.1 KiB
Python

import discord
import json
ENCODING = "utf-8"
class BaseModule:
_client = None
def __init__(self, client):
self._client = client
def load(self):
raise NotImplementedError
async def handle_message(self, message)-> bool:
raise NotImplementedError
async def load_history(self, channel):
messages = [{"id": message.id, "content": message.content, "date": message.created_at.strftime("%d/%m %H:%M:%S")} async for message in channel.history(limit=10)]
return json.dumps(messages, ensure_ascii=False)
async def get_guild_name(self, guildId) -> str:
guild = await self._client.fetch_guild(guildId)
return "[Server={0}]".format(guild.name)
async def get_channel_name(self, channel) -> str:
if isinstance(channel, discord.DMChannel):
dm_channel = await self._client.fetch_channel(channel.id)
return "[DM={0}]".format(dm_channel.recipient.name)
else:
return "[Server={0}] => [Channel={1}]".format(
channel.guild.name, channel.name
)