-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_telegram.py
More file actions
79 lines (66 loc) · 2.32 KB
/
Copy pathfix_telegram.py
File metadata and controls
79 lines (66 loc) · 2.32 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
מוצא ומגדיר את ה-chat_id הנכון לטלגרם
הרץ את זה אחרי ששלחת /start לבוט
"""
import asyncio, os
from pathlib import Path
from dotenv import load_dotenv
load_dotenv(Path.home() / "tv_webhook" / ".env")
TOKEN = os.getenv("TELEGRAM_TOKEN")
ENV_PATH = Path.home() / "tv_webhook" / ".env"
async def main():
import telegram
if not TOKEN:
print("[ERROR] אין TELEGRAM_TOKEN ב-.env")
return
bot = telegram.Bot(token=TOKEN)
me = await bot.get_me()
print(f"\nבוט: @{me.username} (ID: {me.id})")
print("=" * 40)
# מחפש updates
updates = await bot.get_updates(limit=20)
if not updates:
print(f"\n❌ אין הודעות!")
print(f" 1. פתח טלגרם")
print(f" 2. חפש @{me.username}")
print(f" 3. שלח /start")
print(f" 4. הרץ שוב את הסקריפט")
return
print("\nצ'אטים שנמצאו:")
seen = set()
for u in updates:
msg = u.message or u.channel_post
if not msg:
continue
cid = msg.chat.id
name = msg.chat.first_name or msg.chat.title or str(cid)
ctype = msg.chat.type
if cid in seen:
continue
seen.add(cid)
print(f" chat_id: {cid} | שם: {name} | סוג: {ctype}")
# שליחת הודעת אישור
try:
await bot.send_message(chat_id=cid,
text=f"✅ Diamond Scanner מחובר!\nID: {cid}")
print(f" -> הודעת אישור נשלחה!")
except Exception as e:
print(f" -> שגיאה: {e}")
# עדכון .env
if seen:
best_id = list(seen)[0]
content = ENV_PATH.read_text(encoding="utf-8")
if "ALL_CHAT_ID=" in content:
lines = []
for line in content.splitlines():
if line.startswith("ALL_CHAT_ID="):
lines.append(f"ALL_CHAT_ID={best_id}")
else:
lines.append(line)
content = "\n".join(lines)
else:
content += f"\nALL_CHAT_ID={best_id}"
ENV_PATH.write_text(content, encoding="utf-8")
print(f"\n✅ .env עודכן: ALL_CHAT_ID={best_id}")
print(" הרץ עכשיו: python diamond_scanner.py")
asyncio.run(main())