Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.

Commit 33da1ef

Browse files
authored
Add joininfo command to retrieve user join date
1 parent cb3af75 commit 33da1ef

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

tg_tools/joininfo.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import html
2+
from pyrogram.types import Message, User
3+
from pyrogram.enums import ChatType
4+
from pyrogram.errors import UserNotParticipant
5+
6+
from app import BOT, bot
7+
from app.modules.settings import TINY_TIMEOUT, SMALL_TIMEOUT, MEDIUM_TIMEOUT, LONG_TIMEOUT, VERY_LONG_TIMEOUT, LARGE_TIMEOUT
8+
9+
async def get_target_user(bot: BOT, message: Message) -> User | None:
10+
"""Helper function to find the target user."""
11+
if message.replied:
12+
return message.replied.from_user
13+
if message.input:
14+
try:
15+
return await bot.get_users(message.input)
16+
except Exception:
17+
return None
18+
return message.from_user
19+
20+
@bot.add_cmd(cmd=["joininfo", "joindate"])
21+
async def join_date_handler(bot: BOT, message: Message):
22+
"""
23+
CMD: JOININFO / JOINDATE
24+
INFO: Shows when a user joined the current chat.
25+
USAGE:
26+
.joininfo (shows your join date)
27+
.joininfo [reply/id/username]
28+
"""
29+
if message.chat.type not in [ChatType.GROUP, ChatType.SUPERGROUP]:
30+
await message.reply("This command can only be used in groups.", del_in=MEDIUM_TIMEOUT)
31+
return
32+
33+
target_user = await get_target_user(bot, message)
34+
if not target_user:
35+
await message.reply("Could not find the specified user.", del_in=MEDIUM_TIMEOUT)
36+
return
37+
38+
try:
39+
member = await bot.get_chat_member(message.chat.id, target_user.id)
40+
41+
if member.joined_date:
42+
join_date_str = member.joined_date.strftime('%d %b %Y, %H:%M UTC')
43+
response = f"{target_user.mention} joined this chat on:\n<code>{join_date_str}</code>"
44+
else:
45+
response = f"Could not retrieve a specific join date for {target_user.mention}."
46+
47+
await message.reply(response)
48+
49+
except UserNotParticipant:
50+
await message.reply(f"User {target_user.mention} is not a member of this chat.")
51+
except Exception as e:
52+
await message.reply(f"<b>Error:</b> <code>{e}</code>", del_in=LONG_TIMEOUT)

0 commit comments

Comments
 (0)