CBV01 commited on
Commit
05415a5
·
1 Parent(s): 218c279

Fix Admin bulk join resolution and IDE linting errors

Browse files
Files changed (1) hide show
  1. backend/main.py +15 -1
backend/main.py CHANGED
@@ -244,7 +244,17 @@ async def resolve_tg_entity(client, target):
244
  # Optional: DB lookup by ID to find username (much more stable)
245
  try:
246
  conn = get_db_connection()
 
247
  row = conn.execute("SELECT username FROM scraped_groups WHERE id = ?", (target_str,)).fetchone()
 
 
 
 
 
 
 
 
 
248
  if row and row[0]:
249
  resolved_id = row[0]
250
  if hasattr(conn, "close"): conn.close()
@@ -1106,6 +1116,10 @@ async def _scrape_telegram_search(base_query: str, rows: list, queue: Optional[a
1106
  is_private = getattr(chat, 'username', None) is None
1107
  title = getattr(chat, 'title', 'Unknown')
1108
  username = getattr(chat, 'username', None)
 
 
 
 
1109
  participants_count = (
1110
  getattr(chat, 'participants_count', 0)
1111
  or getattr(chat, 'megagroup_participants', 0)
@@ -1113,7 +1127,7 @@ async def _scrape_telegram_search(base_query: str, rows: list, queue: Optional[a
1113
  )
1114
  chat_type = 'channel' if getattr(chat, 'broadcast', False) else 'group'
1115
  item = {
1116
- "id": chat_id_str,
1117
  "title": title,
1118
  "username": username,
1119
  "participants_count": participants_count,
 
244
  # Optional: DB lookup by ID to find username (much more stable)
245
  try:
246
  conn = get_db_connection()
247
+ # Try exact ID match first
248
  row = conn.execute("SELECT username FROM scraped_groups WHERE id = ?", (target_str,)).fetchone()
249
+ if not row:
250
+ # Try with -100 prefix variations
251
+ if target_str.isdigit():
252
+ row = conn.execute("SELECT username FROM scraped_groups WHERE id = ?", (f"-100{target_str}",)).fetchone()
253
+ elif target_str.startswith("-100"):
254
+ # Use replace to avoid index errors in some linters
255
+ clean_id = target_str.replace("-100", "", 1)
256
+ row = conn.execute("SELECT username FROM scraped_groups WHERE id = ?", (clean_id,)).fetchone()
257
+
258
  if row and row[0]:
259
  resolved_id = row[0]
260
  if hasattr(conn, "close"): conn.close()
 
1116
  is_private = getattr(chat, 'username', None) is None
1117
  title = getattr(chat, 'title', 'Unknown')
1118
  username = getattr(chat, 'username', None)
1119
+
1120
+ # PREFER username as the ID if it exists - globally resolvable!
1121
+ final_id = f"@{username}" if username else chat_id_str
1122
+
1123
  participants_count = (
1124
  getattr(chat, 'participants_count', 0)
1125
  or getattr(chat, 'megagroup_participants', 0)
 
1127
  )
1128
  chat_type = 'channel' if getattr(chat, 'broadcast', False) else 'group'
1129
  item = {
1130
+ "id": final_id,
1131
  "title": title,
1132
  "username": username,
1133
  "participants_count": participants_count,