Commented out send_long_message method and auto PEP-8 reginald.py
This commit is contained in:
parent
9209cc568d
commit
a64a07511d
@ -16,7 +16,6 @@ from .weather import time_now, get_current_weather, get_weather_forecast
|
|||||||
from .tools_description import TOOLS
|
from .tools_description import TOOLS
|
||||||
from .debug_stuff import debug
|
from .debug_stuff import debug
|
||||||
|
|
||||||
|
|
||||||
CALLABLE_FUNCTIONS = {
|
CALLABLE_FUNCTIONS = {
|
||||||
# Dictionary with functions to call.
|
# Dictionary with functions to call.
|
||||||
# You can use globals()[func_name](**args) instead, but that's too implicit.
|
# You can use globals()[func_name](**args) instead, but that's too implicit.
|
||||||
@ -80,7 +79,6 @@ class ReginaldCog(PermissionsMixin, BlacklistMixin, MemoryMixin, commands.Cog):
|
|||||||
if not (await self.is_admin(message) or await self.has_access(message.author)):
|
if not (await self.is_admin(message) or await self.has_access(message.author)):
|
||||||
return # Ignore message if user has no permissions
|
return # Ignore message if user has no permissions
|
||||||
|
|
||||||
|
|
||||||
guild = message.guild
|
guild = message.guild
|
||||||
channel_id = str(message.channel.id)
|
channel_id = str(message.channel.id)
|
||||||
user_id = str(message.author.id)
|
user_id = str(message.author.id)
|
||||||
@ -145,10 +143,10 @@ class ReginaldCog(PermissionsMixin, BlacklistMixin, MemoryMixin, commands.Cog):
|
|||||||
"content": f"[{summary['timestamp']}] Topics: {', '.join(summary['topics'])}\n{summary['summary']}"
|
"content": f"[{summary['timestamp']}] Topics: {', '.join(summary['topics'])}\n{summary['summary']}"
|
||||||
})
|
})
|
||||||
|
|
||||||
formatted_messages += [{"role": "user", "content": f"{entry['user']}: {entry['content']}"} for entry in memory]
|
formatted_messages += [{"role": "user", "content": f"{entry['user']}: {entry['content']}"} for entry in
|
||||||
|
memory]
|
||||||
formatted_messages.append({"role": "user", "content": f"{user_name}: {prompt}"})
|
formatted_messages.append({"role": "user", "content": f"{user_name}: {prompt}"})
|
||||||
|
|
||||||
|
|
||||||
##################################################
|
##################################################
|
||||||
# #
|
# #
|
||||||
## Generate AI Response, put into response_text ##
|
## Generate AI Response, put into response_text ##
|
||||||
@ -166,7 +164,8 @@ class ReginaldCog(PermissionsMixin, BlacklistMixin, MemoryMixin, commands.Cog):
|
|||||||
memory.append({"user": "Reginald", "content": response_text})
|
memory.append({"user": "Reginald", "content": response_text})
|
||||||
|
|
||||||
if len(memory) > self.short_term_memory_limit:
|
if len(memory) > self.short_term_memory_limit:
|
||||||
summary = await self.summarize_memory(message, memory[:int(self.short_term_memory_limit * self.summary_retention_ratio)])
|
summary = await self.summarize_memory(message, memory[:int(
|
||||||
|
self.short_term_memory_limit * self.summary_retention_ratio)])
|
||||||
mid_memory.setdefault(channel_id, []).append({
|
mid_memory.setdefault(channel_id, []).append({
|
||||||
"timestamp": datetime.datetime.now().strftime("%Y-%m-%d %H:%M"),
|
"timestamp": datetime.datetime.now().strftime("%Y-%m-%d %H:%M"),
|
||||||
"topics": self.extract_topics_from_summary(summary),
|
"topics": self.extract_topics_from_summary(summary),
|
||||||
@ -174,13 +173,13 @@ class ReginaldCog(PermissionsMixin, BlacklistMixin, MemoryMixin, commands.Cog):
|
|||||||
})
|
})
|
||||||
if len(mid_memory[channel_id]) > self.summary_retention_limit:
|
if len(mid_memory[channel_id]) > self.summary_retention_limit:
|
||||||
mid_memory[channel_id].pop(0)
|
mid_memory[channel_id].pop(0)
|
||||||
memory = memory[-(self.short_term_memory_limit - int(self.short_term_memory_limit * self.summary_retention_ratio)):]
|
memory = memory[-(self.short_term_memory_limit - int(
|
||||||
|
self.short_term_memory_limit * self.summary_retention_ratio)):]
|
||||||
|
|
||||||
short_memory[channel_id] = memory
|
short_memory[channel_id] = memory
|
||||||
|
|
||||||
await self.send_split_message(message.channel, response_text)
|
await self.send_split_message(message.channel, response_text)
|
||||||
|
|
||||||
|
|
||||||
def should_reginald_interject(self, message_content: str) -> bool:
|
def should_reginald_interject(self, message_content: str) -> bool:
|
||||||
"""Determines if Reginald should respond to a message based on keywords."""
|
"""Determines if Reginald should respond to a message based on keywords."""
|
||||||
direct_invocation = {
|
direct_invocation = {
|
||||||
@ -261,7 +260,8 @@ class ReginaldCog(PermissionsMixin, BlacklistMixin, MemoryMixin, commands.Cog):
|
|||||||
await self.config.guild(ctx.guild).openai_api_key.set(api_key)
|
await self.config.guild(ctx.guild).openai_api_key.set(api_key)
|
||||||
await ctx.send("OpenAI API key set successfully.")
|
await ctx.send("OpenAI API key set successfully.")
|
||||||
|
|
||||||
@commands.command(name="reginald_set_listening_channel", help="Set the channel where Reginald listens for messages.")
|
@commands.command(name="reginald_set_listening_channel",
|
||||||
|
help="Set the channel where Reginald listens for messages.")
|
||||||
@commands.has_permissions(administrator=True)
|
@commands.has_permissions(administrator=True)
|
||||||
async def set_listening_channel(self, ctx, channel: discord.TextChannel):
|
async def set_listening_channel(self, ctx, channel: discord.TextChannel):
|
||||||
"""Sets the channel where Reginald will listen for passive responses."""
|
"""Sets the channel where Reginald will listen for passive responses."""
|
||||||
@ -273,7 +273,8 @@ class ReginaldCog(PermissionsMixin, BlacklistMixin, MemoryMixin, commands.Cog):
|
|||||||
await self.config.guild(ctx.guild).listening_channel.set(channel.id)
|
await self.config.guild(ctx.guild).listening_channel.set(channel.id)
|
||||||
await ctx.send(f"✅ Reginald will now listen only in {channel.mention}.")
|
await ctx.send(f"✅ Reginald will now listen only in {channel.mention}.")
|
||||||
|
|
||||||
@commands.command(name="reginald_get_listening_channel", help="Check which channel Reginald is currently listening in.")
|
@commands.command(name="reginald_get_listening_channel",
|
||||||
|
help="Check which channel Reginald is currently listening in.")
|
||||||
@commands.has_permissions(administrator=True)
|
@commands.has_permissions(administrator=True)
|
||||||
async def get_listening_channel(self, ctx):
|
async def get_listening_channel(self, ctx):
|
||||||
"""Displays the current listening channel."""
|
"""Displays the current listening channel."""
|
||||||
@ -288,17 +289,16 @@ class ReginaldCog(PermissionsMixin, BlacklistMixin, MemoryMixin, commands.Cog):
|
|||||||
else:
|
else:
|
||||||
await ctx.send("❌ No listening channel has been set.")
|
await ctx.send("❌ No listening channel has been set.")
|
||||||
|
|
||||||
|
# async def send_long_message(self, ctx, message, prefix: str = ""):
|
||||||
async def send_long_message(self, ctx, message, prefix: str = ""):
|
# """Splits and sends a long message to avoid Discord's 2000-character limit."""
|
||||||
"""Splits and sends a long message to avoid Discord's 2000-character limit."""
|
# chunk_size = 1900 # Leave some space for formatting
|
||||||
chunk_size = 1900 # Leave some space for formatting
|
# if prefix:
|
||||||
if prefix:
|
# prefix_length = len(prefix)
|
||||||
prefix_length = len(prefix)
|
# chunk_size -= prefix_length
|
||||||
chunk_size -= prefix_length
|
#
|
||||||
|
# for i in range(0, len(message), chunk_size):
|
||||||
for i in range(0, len(message), chunk_size):
|
# chunk = message[i:i + chunk_size]
|
||||||
chunk = message[i:i + chunk_size]
|
# await ctx.send(f"{prefix}{chunk}")
|
||||||
await ctx.send(f"{prefix}{chunk}")
|
|
||||||
|
|
||||||
async def send_split_message(self, ctx, content: str, prefix: str = ""):
|
async def send_split_message(self, ctx, content: str, prefix: str = ""):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user