Skip to content

Commit 2d8051e

Browse files
committed
allows to log who used
1 parent e68fb99 commit 2d8051e

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

gemini_pro_bot/handlers.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,31 @@ def new_chat(context: ContextTypes.DEFAULT_TYPE):
3535
'parts': ['Sure.'] # Model's response
3636
},
3737
])
38+
import asyncio
39+
40+
import asyncio
41+
from datetime import datetime
42+
3843
async def start(update: Update, _: ContextTypes.DEFAULT_TYPE) -> None:
3944
"""Send a message when the command /start is issued."""
4045
user = update.effective_user
46+
message = f"Hi {user.mention_html()}!\n\nStart sending messages with me to generate a response.\n\nSend /new to start a new chat session."
47+
48+
# Get the current date and time
49+
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
50+
51+
# Write user details and the timestamp to log file
52+
with open('user_log.txt', 'a') as log_file:
53+
log_file.write(f"{now} - User {user.id} - {user.username} started the chat.\n")
54+
55+
# Send the greeting message to the user
4156
await update.message.reply_html(
42-
f"Hi {user.mention_html()}!\n\nStart sending messages with me to generate a response.\n\nSend /new to start a new chat session.",
57+
message,
4358
# reply_markup=ForceReply(selective=True),
4459
)
4560

4661

62+
4763
async def help_command(update: Update, _: ContextTypes.DEFAULT_TYPE) -> None:
4864
"""Send a message when the command /help is issued."""
4965
help_text = """

user_log.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
User 124235298 - pasou started the chat.
2+
2024-05-30 03:59:01 - User 124235298 - pasou started the chat.

0 commit comments

Comments
 (0)