File size: 1,599 Bytes
3cbeba0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from telegram import ChatType, ParseMode, TelegramError
from telegram.utils.helpers import mention_html
from telegram.ext import Updater
import logging

# Set up logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                     level=logging.INFO)

# Initialize the updater and bot
updater = Updater(token='6558743995:AAGASl5dAQKOiOEB_MSFi4TTja-uf-xXJls', use_context=True)
bot = updater.bot

def search_chats(query):
    results = bot.search_chats(query, limit=10)
    if results:
        for chat in results:
            chat_id = chat.id
            chat_type = chat.type
            chat_name = chat.title
            chat_link = f'https://t.me/{chat.username}' if chat.username else None

            if chat_type in [ChatType.GROUP, ChatType.SUPERGROUP, ChatType.CHANNEL]:
                message = f'Found {chat_type} - <b>{chat_name}</b>'
                if chat_link:
                    message += f' (<a href="{chat_link}">link</a>)'
                message += f' - ID: <code>{chat_id}</code>'
                print(message)
    else:
        print("No chats found for the given query.")

try:
    # Search chats by ID
    chat_id = int(input("Enter Chat ID: "))
    try:
        chat = bot.get_chat(chat_id)
        search_chats(chat.title)
    except TelegramError:
        print("Invalid Chat ID.")

    # Search chats by name
    chat_name = input("Enter Chat Name: ")
    search_chats(chat_name)

except ValueError:
    print("Invalid input. Please enter a number for Chat ID.")

# Start the script
updater.start_polling()
updater.idle()