attempting to make config a property

This commit is contained in:
AllfatherHatt 2025-03-15 18:05:21 +01:00
parent 1f59db6f97
commit f40227d0cd
2 changed files with 12 additions and 5 deletions

View File

@ -11,12 +11,15 @@ from openai import OpenAIError
class MemoryMixin: class MemoryMixin:
"""Handles all memory-related functions for Reginald.""" """Handles all memory-related functions for Reginald."""
def __init__(self, config: Config): @property
self.config = config def config(self):
"""Dynamically fetches the config from the parent cog."""
return self._config # This assumes `ReginaldCog` sets `self._config`
def __init__(self):
self.short_term_memory_limit = 100 self.short_term_memory_limit = 100
self.summary_retention_limit = 25 self.summary_retention_limit = 25
self.summary_retention_ratio = 0.8 self.summary_retention_ratio = 0.8
@commands.command(name="reginald_clear_short", help="Clears short-term memory for this channel.") @commands.command(name="reginald_clear_short", help="Clears short-term memory for this channel.")
@commands.has_permissions(administrator=True) @commands.has_permissions(administrator=True)

View File

@ -14,13 +14,17 @@ from .memory import MemoryMixin
class ReginaldCog(commands.Cog, PermissionsMixin, BlacklistMixin, MemoryMixin): class ReginaldCog(commands.Cog, PermissionsMixin, BlacklistMixin, MemoryMixin):
def __init__(self, bot): def __init__(self, bot):
super().__init__() super().__init__() # ✅ Call parent class constructor first
self.bot = bot self.bot = bot
self.config = Config.get_conf(self, identifier=71717171171717) self.config = Config.get_conf(self, identifier=71717171171717)
self.default_listening_channel = 1085649787388428370 self.default_listening_channel = 1085649787388428370
self.memory_locks = {} self.memory_locks = {}
# Properly Registered Configuration Keys # ✅ Ensure `MemoryMixin` can access `config`
self._config = self.config # 🔥 This is the key part that enables `MemoryMixin.config`
# ✅ Properly Registered Configuration Keys
default_global = {"openai_model": "gpt-4o-mini"} default_global = {"openai_model": "gpt-4o-mini"}
default_guild = { default_guild = {
"openai_api_key": None, "openai_api_key": None,