Skip to content

Commit 5163eb3

Browse files
authored
Update chat.py
1 parent c46b83e commit 5163eb3

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

cogs/chat.py

+14-22
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@
77
class Chat(commands.Cog):
88
def __init__(self, bot: commands.Bot):
99
self.bot = bot
10-
self.chat_histories = {}
1110

12-
@app_commands.command(name="chat", description="Start chatting with Ai")
11+
@app_commands.command(name="chat", description="Start chatting with AI")
1312
@app_commands.describe(message="What is in your mind?")
1413
async def chat(self, interaction: discord.Interaction, message: str):
1514
user_id = interaction.user.id
15+
chat_histories = self.bot.conversation_histories
1616

17-
if user_id not in self.chat_histories:
18-
self.chat_histories[user_id] = []
17+
if user_id not in chat_histories:
18+
chat_histories[user_id] = []
1919

20-
self.chat_histories[user_id].append({"role": "user", "parts": [message]})
20+
chat_histories[user_id].append({"role": "user", "parts": [message]})
2121

2222
await interaction.response.defer()
2323

2424
try:
25-
response = get_response(self.chat_histories[user_id])
25+
response = get_response(chat_histories[user_id])
2626
if response:
27-
self.chat_histories[user_id].append({"role": "model", "parts": [response]})
27+
chat_histories[user_id].append({"role": "model", "parts": [response]})
2828
if len(response) >= 2000:
2929
await paginated_message(interaction.channel, response)
3030
else:
@@ -34,16 +34,6 @@ async def chat(self, interaction: discord.Interaction, message: str):
3434
except Exception as e:
3535
await interaction.followup.send("Ugh, my brain hurts, can you say that again?")
3636

37-
@app_commands.command(name="wipe", description="Wipe chat history")
38-
async def wipe(self, interaction: discord.Interaction):
39-
user_id = interaction.user.id
40-
41-
if user_id in self.chat_histories:
42-
self.chat_histories[user_id] = []
43-
await interaction.response.send_message("Your chat history has been wiped.")
44-
else:
45-
await interaction.response.send_message("You don't have any chat history with me")
46-
4737
@commands.Cog.listener()
4838
async def on_message(self, message):
4939
if message.author == self.bot.user:
@@ -58,16 +48,18 @@ async def on_mention(self, message):
5848
if not mention_content:
5949
mention_content = "Hello, how can I assist you today?"
6050

61-
if user_id not in self.chat_histories:
62-
self.chat_histories[user_id] = []
51+
chat_histories = self.bot.conversation_histories
52+
53+
if user_id not in chat_histories:
54+
chat_histories[user_id] = []
6355

64-
self.chat_histories[user_id].append({"role": "user", "parts": [mention_content]})
56+
chat_histories[user_id].append({"role": "user", "parts": [mention_content]})
6557

6658
async with message.channel.typing():
6759
try:
68-
response = get_response(self.chat_histories[user_id])
60+
response = get_response(chat_histories[user_id])
6961
if response:
70-
self.chat_histories[user_id].append({"role": "model", "parts": [response]})
62+
chat_histories[user_id].append({"role": "model", "parts": [response]})
7163
if len(response) >= 2000:
7264
await paginated_message(message.channel, response)
7365
else:

0 commit comments

Comments
 (0)