You're the star of the show now baby!
This commit is contained in:
parent
d89a086420
commit
4ff0630d66
2 changed files with 23 additions and 3 deletions
18
bot.py
18
bot.py
|
@ -387,6 +387,24 @@ async def on_message(message: discord.Message) -> None:
|
|||
cleaned_message: str = preprocess_message(formatted_message)
|
||||
if cleaned_message:
|
||||
memory.append(cleaned_message)
|
||||
message_metadata = {
|
||||
"user_id": str(message.author.id),
|
||||
"user_name": str(message.author),
|
||||
"guild_id": str(message.guild.id) if message.guild else "DM",
|
||||
"guild_name": str(message.guild.name) if message.guild else "DM",
|
||||
"channel_id": str(message.channel.id),
|
||||
"channel_name": str(message.channel),
|
||||
"message": message.content,
|
||||
"timestamp": time.time()
|
||||
}
|
||||
try:
|
||||
if isinstance(memory, list):
|
||||
memory.append({"_meta": message_metadata})
|
||||
else:
|
||||
logger.warning("Memory is not a list; can't append metadata")
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to append metadata to memory: {e}")
|
||||
|
||||
save_memory(memory)
|
||||
|
||||
sentiment_score = is_positive(message.content) # doesnt work but im scared to change the logic now please ignore
|
||||
|
|
|
@ -34,13 +34,15 @@ def save_memory(memory):
|
|||
with open(MEMORY_FILE, "w") as f:
|
||||
json.dump(memory, f, indent=4)
|
||||
|
||||
# Train a Markov model using memory and optional additional data
|
||||
def train_markov_model(memory, additional_data=None):
|
||||
if not memory:
|
||||
return None
|
||||
text = "\n".join(memory)
|
||||
filtered_memory = [line for line in memory if isinstance(line, str)]
|
||||
if additional_data:
|
||||
text += "\n" + "\n".join(additional_data)
|
||||
filtered_memory.extend(line for line in additional_data if isinstance(line, str))
|
||||
if not filtered_memory:
|
||||
return None
|
||||
text = "\n".join(filtered_memory)
|
||||
model = markovify.NewlineText(text, state_size=2)
|
||||
return model
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue