1
- import { modeChatGPT } from './modes/chatGPT.js'
1
+ import { cleanContext , modeChatGPT } from './modes/chatGPT.js'
2
2
import events from 'events'
3
3
import { db } from '../db/index.js'
4
4
import { removeQueryFromPrevMessage } from './hoc/removeQueryFromPrevMsg.js'
5
5
import { modesChatGPT } from '../constants/modes.js'
6
+ import { INITIAL_SESSION } from '../constants/index.js'
7
+ import { autoRemoveMessage } from './hoc/autoRemoveMessage.js'
8
+ import { keyboardChatGPT } from './keyboard/chat_gpt.js'
6
9
7
10
export const onMessageTextDefault = async ( bot , msg , match , sudoUser , t ) => {
8
11
const { id : chatID } = msg . chat
@@ -24,8 +27,8 @@ export const onMessageTextDefault = async (bot, msg, match, sudoUser, t) => {
24
27
...optionsGeneral ,
25
28
reply_markup : {
26
29
inline_keyboard : [
27
- [ { text : t ( 'btn_new_chat' ) , callback_data : ' create_new_chat' } ,
28
- { text : t ( 'btn_change_mode' ) , callback_data : ' change_chat_mode' } ]
30
+ [ { text : t ( 'btn_new_chat' ) , callback_data : ` create_new_chat${ msgId } ` } ,
31
+ { text : t ( 'btn_change_mode' ) , callback_data : ` change_chat_mode${ msgId } ` } ]
29
32
]
30
33
}
31
34
}
@@ -41,14 +44,19 @@ export const onMessageTextDefault = async (bot, msg, match, sudoUser, t) => {
41
44
42
45
const eventEmitter = new events . EventEmitter ( )
43
46
44
- eventEmitter . on ( 'change_chat_mode' , async function ( ) {
47
+ eventEmitter . on ( `create_new_chat${ msgId } ` , async function ( ) {
48
+ await autoRemoveMessage ( '✅ ' + t ( 'btn_new_chat' ) , bot , chatID , { } , 10000 )
49
+ await cleanContext ( chatID )
50
+ } )
51
+
52
+ eventEmitter . on ( `change_chat_mode${ msgId } ` , async function ( ) {
45
53
await bot . editMessageText (
46
54
firstMessage . text ,
47
55
{
48
56
message_id : firstMessage . message_id ,
49
57
chat_id : chatID ,
50
58
reply_markup : {
51
- inline_keyboard : modesChatGPT . map ( ( mode ) => [ { text : mode . name , callback_data : mode . code } ] )
59
+ inline_keyboard : modesChatGPT . map ( ( mode ) => [ { text : t ( mode . name ) , callback_data : mode . code } ] )
52
60
}
53
61
}
54
62
) . catch ( ( err ) => {
@@ -76,7 +84,8 @@ export const onMessageTextDefault = async (bot, msg, match, sudoUser, t) => {
76
84
await db . subscriber . update (
77
85
{ modeGPT : modesChatGPT [ i ] . code } ,
78
86
{ where : { chat_id : chatID } }
79
- ) . then ( res => {
87
+ ) . then ( async res => {
88
+ await removeQueryFromPrevMessage ( bot , msg . chat . id , firstMessage )
80
89
// bot.deleteMessage(chatID, firstMessage.message_id).catch(err => console.error(err))
81
90
firstMessage = modeChatGPT ( bot , msg , {
82
91
message_id : firstMessage . message_id ,
0 commit comments