File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change 4
4
* .code-workspace
5
5
/src /__pycache__
6
6
/testing
7
+ requirements copy.txt
Original file line number Diff line number Diff line change 28
28
database = Database (DB_DSN )
29
29
chatgpt = MyChatGPT (database )
30
30
31
+ async def keep_typing (chat_id ):
32
+ asyncio .sleep (5 ) # wait before "typing" the text
33
+ while True :
34
+ await bot .send_chat_action (chat_id , "typing" )
35
+ await asyncio .sleep (4 ) # Refresh every 4s (before 5s limit)
31
36
32
37
33
38
# /start
@@ -50,7 +55,11 @@ async def message_handler(message: Message):
50
55
user_info = f"Received message from { message .from_user .full_name } (ID: { message .from_user .id } )"
51
56
print (user_info ) # Log user info (use dp.message.middleware(LoggingMiddleware()); class LoggingMiddleware(BaseMiddleware):)
52
57
print ("\t Q:" , message .text )
58
+
59
+ task = asyncio .create_task (keep_typing (message .chat .id )) # change this (message.chat.id) if you ever plan on adding groupchat support
53
60
answer = await chatgpt .message_chatgpt (message .text , message .from_user .id )
61
+ task .cancel ()
62
+
54
63
print ("\t A:" , answer )
55
64
await message .answer (answer )
56
65
You can’t perform that action at this time.
0 commit comments