Загрузка данных
import asyncio
from datetime import datetime, timedelta, timezone
from telethon import TelegramClient
from telethon.errors import (
ChannelPrivateError,
FloodWaitError,
UsernameInvalidError,
UsernameNotOccupiedError,
)
API_ID = 35901392
API_HASH = "08ab29c9da01a4f3eaf10f3baa7200f2"
SESSION_NAME = "session_acc3"
INPUT_FILE = "usernames.txt"
CAT_1 = "cat_1_bec_o365.txt"
CAT_2A = "cat_2a_active_hacking.txt"
CAT_2B = "cat_2b_ads_hacking.txt"
CAT_3 = "cat_3_unrelated_russian_inactive.txt"
CAT_4 = "cat_4_dead_groups.txt"
KW_O365 = [
"o365",
"office 365",
"microsoft 365",
"office365",
"outlook",
"smtp",
"imap",
"exchange",
"mail access",
"imap logs",
"mail pass",
"mailbase",
"azure",
"entra id",
"webmail",
"cpanel",
"corporate leads",
"business email",
"inbox fwd",
"fwd rule",
"bec",
"tdata",
"business lead",
"corp mail",
]
KW_HACKING = [
"hacking",
"exploit",
"fraud",
"carding",
"stealer",
"cves",
"pentest",
"ddos",
"botnet",
"phishing",
"malware",
"credentials",
"combolists",
"redline",
"vidar",
"raccoon",
"lumma",
"source code",
"0day",
"rat",
"sqli",
"bypass",
"dump",
"cracked",
"cookies",
"rdp",
"checker",
"combo",
]
KW_ADS = [
"selling",
"buying",
"price",
"pm me",
"escrow",
"vcc",
"for sale",
"shop",
"store",
"deal",
"discount",
"bulk",
"wts",
"wtb",
"$",
"usd",
"crypto accepted",
"order now",
]
async def append_to_file(filename, text):
with open(filename, "a", encoding="utf-8") as f:
f.write(text + "\n")
def has_cyrillic(text):
return any("\u0400" <= char <= "\u04ff" for char in text.lower())
async def analyze_chat(client, entity):
now = datetime.now(timezone.utc)
one_day_ago = now - timedelta(days=1)
messages_24h = []
text_corpus = []
senders = set()
try:
async for msg in client.iter_messages(entity, limit=20):
if msg.text:
text_corpus.append(msg.text)
if msg.date and msg.date >= one_day_ago:
messages_24h.append(msg)
sender = msg.sender_id or msg.from_id
if sender:
senders.add(sender)
except Exception:
pass
is_active = len(messages_24h) >= 3 and len(senders) >= 2
return is_active, " ".join(text_corpus)
async def main():
try:
with open(INPUT_FILE, "r", encoding="utf-8") as f:
usernames = [line.strip().lstrip("@") for line in f if line.strip()]
except FileNotFoundError:
print(f"Файл {INPUT_FILE} не найден.")
return
print(f"Загружено {len(usernames)} строк. Запуск проверки...")
async with TelegramClient(SESSION_NAME, API_ID, API_HASH) as client:
for idx, username in enumerate(usernames, 1):
while True:
try:
entity = await client.get_entity(username)
title = getattr(entity, "title", "") or ""
is_active, chat_body = await analyze_chat(client, entity)
full_content = f"{title} {chat_body}".strip()
full_content_lower = full_content.lower()
if has_cyrillic(full_content):
await append_to_file(CAT_3, f"@{username} | {title} (RU content)")
print(f"[{idx}/{len(usernames)}] [Cat 3 - RU]: @{username}")
break
is_o365 = any(kw in full_content_lower for kw in KW_O365)
is_hack = any(kw in full_content_lower for kw in KW_HACKING)
if not is_o365 and not is_hack:
await append_to_file(
CAT_3, f"@{username} | {title} (Unrelated topic)"
)
print(
f"[{idx}/{len(usernames)}] [Cat 3 - Не по теме]: @{username}"
)
break
if not is_active:
await append_to_file(CAT_3, f"@{username} | {title} (Inactive chat)")
print(
f"[{idx}/{len(usernames)}] [Cat 3 - Мертвый чат]: @{username}"
)
break
if is_o365:
await append_to_file(CAT_1, f"@{username} | {title}")
print(f"[{idx}/{len(usernames)}] [Cat 1 - O365/BEC]: @{username}")
elif is_hack:
if any(ad in full_content_lower for ad in KW_ADS):
await append_to_file(CAT_2B, f"@{username} | {title}")
print(f"[{idx}/{len(usernames)}] [Cat 2b - Ads]: @{username}")
else:
await append_to_file(CAT_2A, f"@{username} | {title}")
print(f"[{idx}/{len(usernames)}] [Cat 2a - Active]: @{username}")
break
except (
UsernameInvalidError,
UsernameNotOccupiedError,
ValueError,
ChannelPrivateError,
):
await append_to_file(CAT_4, f"@{username}")
print(f"[{idx}/{len(usernames)}] [Cat 4 - Dead/Private]: @{username}")
break
except FloodWaitError as e:
print(f"Лимит запросов. Ожидание {e.seconds} сек...")
await asyncio.sleep(e.seconds + 2)
except Exception:
await append_to_file(CAT_4, f"@{username}")
print(
f"[{idx}/{len(usernames)}] [Cat 4 - Inaccessible]: @{username}"
)
break
await asyncio.sleep(1.8)
print("Обработка завершена.")
if __name__ == "__main__":
asyncio.run(main())