ooh
This commit is contained in:
parent
493da92d1c
commit
dc777f25ef
1 changed files with 13 additions and 13 deletions
26
bot.py
26
bot.py
|
@ -9,6 +9,7 @@ import os
|
|||
import time
|
||||
import re
|
||||
from dotenv import load_dotenv
|
||||
import psutil
|
||||
load_dotenv()
|
||||
# download NLTK data files
|
||||
nltk.download('punkt')
|
||||
|
@ -71,6 +72,12 @@ async def on_ready():
|
|||
print(f"Logged in as {bot.user}")
|
||||
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_gifs = [
|
||||
|
@ -102,7 +109,7 @@ bot.help_command = None
|
|||
async def on_message(message):
|
||||
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:
|
||||
response = None
|
||||
for _ in range(10):
|
||||
|
@ -111,9 +118,8 @@ async def on_message(message):
|
|||
response = improve_sentence_coherence(response)
|
||||
generated_sentences.add(response)
|
||||
break
|
||||
|
||||
|
||||
if response:
|
||||
# Use message.channel.typing() instead of ctx.typing()
|
||||
async with message.channel.typing():
|
||||
cleaned_response = re.sub(r'[^\w\s]', '', response).lower()
|
||||
coherent_response = rephrase_for_coherence(cleaned_response)
|
||||
|
@ -122,30 +128,24 @@ async def on_message(message):
|
|||
gif_url = random.choice(positive_gifs)
|
||||
combined_message = f"{coherent_response}\n[jif]({gif_url})"
|
||||
await message.channel.send(combined_message)
|
||||
print(f"Goober: {combined_message}")
|
||||
else:
|
||||
await message.channel.send(coherent_response)
|
||||
print(f"Goober: {coherent_response}")
|
||||
else:
|
||||
await message.channel.send(coherent_response)
|
||||
print(f"Goober: {coherent_response}")
|
||||
else:
|
||||
await message.channel.send("I have nothing to say right now!")
|
||||
else:
|
||||
await message.channel.send("I need to learn more from messages before I can talk.")
|
||||
else:
|
||||
return
|
||||
|
||||
if message.content:
|
||||
if message.content and message.author.id != bot.user.id :
|
||||
formatted_message = append_mentions_to_18digit_integer(message.content)
|
||||
cleaned_message = preprocess_message(formatted_message)
|
||||
if cleaned_message:
|
||||
memory.append(cleaned_message)
|
||||
save_memory(memory)
|
||||
markov_model = train_markov_model(memory)
|
||||
|
||||
print(f"MessageAI: {message.content}")
|
||||
await bot.process_commands(message)
|
||||
# Still process commands even from humans
|
||||
if message.content and not message.author.bot:
|
||||
await bot.process_commands(message)
|
||||
|
||||
|
||||
@bot.command()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue