commit before utter laptop death

This commit is contained in:
WhatDidYouExpect 2025-07-23 16:58:21 +02:00
parent 4e111b410d
commit d6b51c787a
11 changed files with 163 additions and 221 deletions

51
main.py
View file

@ -31,7 +31,8 @@ import logging
from modules.settings import Settings as SettingsManager
from modules.permission import requires_admin
from modules.volta.main import _
from modules.version import check_for_update
check_for_update()
logger = logging.getLogger("goober")
logger.setLevel(logging.DEBUG)
@ -85,15 +86,18 @@ class MessageMetadata(TypedDict):
# Constants with type hints
positive_gifs: List[str] = settings["bot"]["misc"]["positive_gifs"]
name = settings["name"]
currenthash: str = ""
launched: bool = False
slash_commands_enabled: bool = False
# Set up Discord bot intents and create bot instance
intents: discord.Intents = discord.Intents.default()
intents.messages = True
intents.presences = True
intents.members = True
intents.message_content = True
bot: commands.Bot = commands.Bot(
command_prefix=settings["bot"]["prefix"],
intents=intents,
@ -104,11 +108,6 @@ bot: commands.Bot = commands.Bot(
# Load memory and Markov model for text generation
memory: List[str | Dict[Literal["_meta"], MessageMetadata]] = load_memory()
markov_model: Optional[markovify.Text] = load_markov_model()
if not markov_model:
logger.error(_('markov_model_not_found'))
memory = load_memory()
markov_model = train_markov_model(memory)
generated_sentences: Set[str] = set()
used_words: Set[str] = set()
@ -150,7 +149,7 @@ async def on_ready() -> None:
synced: List[discord.app_commands.AppCommand] = await bot.tree.sync()
logger.info(f"{_('synced_commands')} {len(synced)} {_('synced_commands2')}")
logger.info(_('started'))
logger.info(_('started').format(name=name))
except discord.errors.Forbidden as perm_error:
logger.error(f"Permission error while syncing commands: {perm_error}")
@ -174,34 +173,6 @@ async def on_ready() -> None:
launched = True
bot.remove_command('help')
# Command: Show help information
@bot.hybrid_command(description=f"{(_('command_desc_help'))}")
async def help(ctx: commands.Context) -> None:
embed: discord.Embed = discord.Embed(
title=f"{(_('command_help_embed_title'))}",
description=f"{(_('command_help_embed_desc'))}",
color=Colour(0x000000)
)
command_categories: Dict[str, List[str]] = {
f"{(_('command_help_categories_general'))}": ["mem", "talk", "about", "ping", "impact", "demotivator", "help"],
f"{(_('command_help_categories_admin'))}": ["stats", "retrain", "setlanguage"]
}
custom_commands: List[str] = []
for cog_name, cog in bot.cogs.items():
for command in cog.get_commands():
if command.name not in command_categories[f"{(_('command_help_categories_general'))}"] and command.name not in command_categories[f"{(_('command_help_categories_admin'))}"]:
custom_commands.append(command.name)
if custom_commands:
embed.add_field(name=f"{(_('command_help_categories_custom'))}", value="\n".join([f"{PREFIX}{command}" for command in custom_commands]), inline=False)
for category, commands_list in command_categories.items():
commands_in_category: str = "\n".join([f"{PREFIX}{command}" for command in commands_list])
embed.add_field(name=category, value=commands_in_category, inline=False)
await send_message(ctx, embed=embed)
@bot.event
async def on_command_error(ctx: commands.Context, error: commands.CommandError) -> None:
@ -226,7 +197,7 @@ async def on_command_error(ctx: commands.Context, error: commands.CommandError)
# Event: Called on every message
@bot.event
async def on_message(message: discord.Message) -> None:
global memory, markov_model
global memory
EMOJIS = [
"\U0001f604",
"\U0001f44d",
@ -250,12 +221,6 @@ async def on_message(message: discord.Message) -> None:
await bot.process_commands(message)
return
if (
profanity.contains_profanity(message.content)
and settings["bot"]["misc"]["block_profanity"]
):
return
if message.content:
if not settings["bot"]["user_training"]:
return