7
7
class Chat (commands .Cog ):
8
8
def __init__ (self , bot : commands .Bot ):
9
9
self .bot = bot
10
- self .chat_histories = {}
11
10
12
- @app_commands .command (name = "chat" , description = "Start chatting with Ai " )
11
+ @app_commands .command (name = "chat" , description = "Start chatting with AI " )
13
12
@app_commands .describe (message = "What is in your mind?" )
14
13
async def chat (self , interaction : discord .Interaction , message : str ):
15
14
user_id = interaction .user .id
15
+ chat_histories = self .bot .conversation_histories
16
16
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 ] = []
19
19
20
- self . chat_histories [user_id ].append ({"role" : "user" , "parts" : [message ]})
20
+ chat_histories [user_id ].append ({"role" : "user" , "parts" : [message ]})
21
21
22
22
await interaction .response .defer ()
23
23
24
24
try :
25
- response = get_response (self . chat_histories [user_id ])
25
+ response = get_response (chat_histories [user_id ])
26
26
if response :
27
- self . chat_histories [user_id ].append ({"role" : "model" , "parts" : [response ]})
27
+ chat_histories [user_id ].append ({"role" : "model" , "parts" : [response ]})
28
28
if len (response ) >= 2000 :
29
29
await paginated_message (interaction .channel , response )
30
30
else :
@@ -34,16 +34,6 @@ async def chat(self, interaction: discord.Interaction, message: str):
34
34
except Exception as e :
35
35
await interaction .followup .send ("Ugh, my brain hurts, can you say that again?" )
36
36
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
-
47
37
@commands .Cog .listener ()
48
38
async def on_message (self , message ):
49
39
if message .author == self .bot .user :
@@ -58,16 +48,18 @@ async def on_mention(self, message):
58
48
if not mention_content :
59
49
mention_content = "Hello, how can I assist you today?"
60
50
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 ] = []
63
55
64
- self . chat_histories [user_id ].append ({"role" : "user" , "parts" : [mention_content ]})
56
+ chat_histories [user_id ].append ({"role" : "user" , "parts" : [mention_content ]})
65
57
66
58
async with message .channel .typing ():
67
59
try :
68
- response = get_response (self . chat_histories [user_id ])
60
+ response = get_response (chat_histories [user_id ])
69
61
if response :
70
- self . chat_histories [user_id ].append ({"role" : "model" , "parts" : [response ]})
62
+ chat_histories [user_id ].append ({"role" : "model" , "parts" : [response ]})
71
63
if len (response ) >= 2000 :
72
64
await paginated_message (message .channel , response )
73
65
else :
0 commit comments