This commit is contained in:
WhatDidYouExpect 2025-07-21 21:34:28 +02:00
parent 493da92d1c
commit dc777f25ef

24
bot.py
View file

@ -9,6 +9,7 @@ import os
import time import time
import re import re
from dotenv import load_dotenv from dotenv import load_dotenv
import psutil
load_dotenv() load_dotenv()
# download NLTK data files # download NLTK data files
nltk.download('punkt') nltk.download('punkt')
@ -71,6 +72,12 @@ async def on_ready():
print(f"Logged in as {bot.user}") print(f"Logged in as {bot.user}")
post_message.start() post_message.start()
@bot.command()
async def mem(ctx):
process = psutil.Process(os.getpid())
mem = process.memory_info().rss
await ctx.send(f"Total memory used: {mem / 1024 / 1024:.2f} MB")
positive_keywords = ["happy", "good", "great", "amazing", "awesome", "joy", "love", "fantastic", "positive", "cheerful", "victory", "favorite", "lmao", "lol", "xd", "XD", "xD", "Xd"] positive_keywords = ["happy", "good", "great", "amazing", "awesome", "joy", "love", "fantastic", "positive", "cheerful", "victory", "favorite", "lmao", "lol", "xd", "XD", "xD", "Xd"]
positive_gifs = [ positive_gifs = [
@ -102,7 +109,7 @@ bot.help_command = None
async def on_message(message): async def on_message(message):
global memory, markov_model, last_random_talk_time global memory, markov_model, last_random_talk_time
if message.author.id == MESSAGEAIID: if message.author.bot and message.author.id != bot.user.id:
if markov_model: if markov_model:
response = None response = None
for _ in range(10): for _ in range(10):
@ -113,7 +120,6 @@ async def on_message(message):
break break
if response: if response:
# Use message.channel.typing() instead of ctx.typing()
async with message.channel.typing(): async with message.channel.typing():
cleaned_response = re.sub(r'[^\w\s]', '', response).lower() cleaned_response = re.sub(r'[^\w\s]', '', response).lower()
coherent_response = rephrase_for_coherence(cleaned_response) coherent_response = rephrase_for_coherence(cleaned_response)
@ -122,30 +128,24 @@ async def on_message(message):
gif_url = random.choice(positive_gifs) gif_url = random.choice(positive_gifs)
combined_message = f"{coherent_response}\n[jif]({gif_url})" combined_message = f"{coherent_response}\n[jif]({gif_url})"
await message.channel.send(combined_message) await message.channel.send(combined_message)
print(f"Goober: {combined_message}")
else: else:
await message.channel.send(coherent_response) await message.channel.send(coherent_response)
print(f"Goober: {coherent_response}")
else: else:
await message.channel.send(coherent_response) await message.channel.send(coherent_response)
print(f"Goober: {coherent_response}")
else: else:
await message.channel.send("I have nothing to say right now!") await message.channel.send("I have nothing to say right now!")
else: else:
await message.channel.send("I need to learn more from messages before I can talk.") await message.channel.send("I need to learn more from messages before I can talk.")
else: if message.content and message.author.id != bot.user.id :
return
if message.content:
formatted_message = append_mentions_to_18digit_integer(message.content) formatted_message = append_mentions_to_18digit_integer(message.content)
cleaned_message = preprocess_message(formatted_message) cleaned_message = preprocess_message(formatted_message)
if cleaned_message: if cleaned_message:
memory.append(cleaned_message) memory.append(cleaned_message)
save_memory(memory) save_memory(memory)
markov_model = train_markov_model(memory) markov_model = train_markov_model(memory)
# Still process commands even from humans
print(f"MessageAI: {message.content}") if message.content and not message.author.bot:
await bot.process_commands(message) await bot.process_commands(message)
@bot.command() @bot.command()