Add channel name to the messages, fix things.

This commit is contained in:
Fjerkroa Auto
2023-03-22 23:28:32 +01:00
parent d23e780248
commit 95e810db7a
3 changed files with 12 additions and 6 deletions
+2 -1
View File
@@ -17,9 +17,10 @@ class AIMessageBase(object):
class AIMessage(AIMessageBase):
def __init__(self, user: str, message: str) -> None:
def __init__(self, user: str, message: str, channel: str = "chat") -> None:
self.user = user
self.message = message
self.channel = channel
class AIResponse(AIMessageBase):
+8 -3
View File
@@ -40,10 +40,12 @@ class FjerkroaBot(commands.Bot):
@classmethod
def load_config(self, config_file: str = "config.toml"):
logging.info(f"config file {config_file} changed, reloading.")
with open(config_file, encoding='utf-8') as file:
return toml.load(file)
def on_config_file_modified(self, event):
logging.info(f"file {event.src_path} modified")
if event.src_path == self.config_file:
self.config = self.load_config(self.config_file)
self.airesponder.config = self.config
@@ -60,19 +62,22 @@ class FjerkroaBot(commands.Bot):
async def on_member_join(self, member):
logging.info(f"User {member.name} joined")
msg = AIMessage(member.name, self.config['join-message'].replace('{name}', member.name))
if self.welcome_channel is not None:
msg = AIMessage(member.name, self.config['join-message'].replace('{name}', member.name), str(self.welcome_channel.name))
await self.respond(msg, self.welcome_channel)
async def on_message(self, message: Message) -> None:
if self.user is not None and message.author.id == self.user.id:
return
msg = AIMessage(message.author.name, str(message.content).strip())
message_content = str(message.content).strip()
if len(message_content) < 1:
return
msg = AIMessage(message.author.name, message_content, str(message.channel.name))
await self.respond(msg, message.channel)
async def respond(self, message: AIMessage, channel: TextChannel) -> None:
try:
channel_name = channel.name
channel_name = str(channel.name)
except Exception:
channel_name = str(channel.id)
logging.info(f"handle message {str(message)} for channel {channel_name}")