1- import { modeChatGPT } from './modes/chatGPT.js'
1+ import { cleanContext , modeChatGPT } from './modes/chatGPT.js'
22import events from 'events'
33import { db } from '../db/index.js'
44import { removeQueryFromPrevMessage } from './hoc/removeQueryFromPrevMsg.js'
55import { 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'
69
710export const onMessageTextDefault = async ( bot , msg , match , sudoUser , t ) => {
811 const { id : chatID } = msg . chat
@@ -24,8 +27,8 @@ export const onMessageTextDefault = async (bot, msg, match, sudoUser, t) => {
2427 ...optionsGeneral ,
2528 reply_markup : {
2629 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 } ` } ]
2932 ]
3033 }
3134 }
@@ -41,14 +44,19 @@ export const onMessageTextDefault = async (bot, msg, match, sudoUser, t) => {
4144
4245 const eventEmitter = new events . EventEmitter ( )
4346
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 ( ) {
4553 await bot . editMessageText (
4654 firstMessage . text ,
4755 {
4856 message_id : firstMessage . message_id ,
4957 chat_id : chatID ,
5058 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 } ] )
5260 }
5361 }
5462 ) . catch ( ( err ) => {
@@ -76,7 +84,8 @@ export const onMessageTextDefault = async (bot, msg, match, sudoUser, t) => {
7684 await db . subscriber . update (
7785 { modeGPT : modesChatGPT [ i ] . code } ,
7886 { where : { chat_id : chatID } }
79- ) . then ( res => {
87+ ) . then ( async res => {
88+ await removeQueryFromPrevMessage ( bot , msg . chat . id , firstMessage )
8089 // bot.deleteMessage(chatID, firstMessage.message_id).catch(err => console.error(err))
8190 firstMessage = modeChatGPT ( bot , msg , {
8291 message_id : firstMessage . message_id ,
0 commit comments