TRiG3Rx

Im2015Activedropper

Jun 9th, 2026 (edited)
16
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.58 KB | None | 0 0
  1. import re
  2. import logging
  3. import sqlite3
  4. from datetime import datetime, timedelta, timezone
  5. from telegram import Update
  6. from telegram.ext import Application, CommandHandler, MessageHandler, ContextTypes, filters
  7.  
  8. # ==================== CONFIGURATION ====================
  9. TOKEN = "8218725801:AAEz3zZYChRwPNhSCUDlE1psOiVAAg6oT4U"
  10. CHANNEL_ID = -1003540313095
  11. # =======================================================
  12.  
  13. # Enable logging
  14. logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
  15.  
  16. # Regex filter to capture variations of: e, E, even, EVEN, o, O, odd, ODD (including mixed cases with numbers e.g., e24, o19)
  17. CHAT_FILTER_REGEX = re.compile(r'(even|odd|e|o)', re.IGNORECASE)
  18.  
  19. # --- DATABASE SETUP ---
  20. def init_db():
  21. conn = sqlite3.connect('palaro.db')
  22. cursor = conn.cursor()
  23. cursor.execute('''
  24. CREATE TABLE IF NOT EXISTS chats (
  25. id INTEGER PRIMARY KEY AUTOINCREMENT,
  26. user_identifier TEXT,
  27. timestamp DATETIME
  28. )
  29. ''')
  30. conn.commit()
  31. conn.close()
  32.  
  33. # Background Listener: Logs every qualified channel chat into the database
  34. async def track_messages(update: Update, context: ContextTypes.DEFAULT_TYPE):
  35. # Ensure messages are processed only from your designated channel
  36. if update.effective_chat.id != CHANNEL_ID:
  37. return
  38.  
  39. msg = update.effective_message
  40. if msg.text or msg.caption:
  41. text = msg.text or msg.caption
  42.  
  43. # If text matches our game criteria (even if mixed with numbers), log it
  44. if CHAT_FILTER_REGEX.search(text):
  45. if msg.author_signature:
  46. user_identifier = f"✍️ {msg.author_signature}"
  47. elif msg.from_user:
  48. user = msg.from_user
  49. user_identifier = f"@{user.username}" if user.username else f"ID: `{user.id}`"
  50. elif msg.sender_chat:
  51. user_identifier = f"📢 {msg.sender_chat.title}"
  52. else:
  53. return
  54.  
  55. now = datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S')
  56.  
  57. conn = sqlite3.connect('palaro.db')
  58. cursor = conn.cursor()
  59. cursor.execute('INSERT INTO chats (user_identifier, timestamp) VALUES (?, ?)', (user_identifier, now))
  60. conn.commit()
  61. conn.close()
  62.  
  63. # Command Processor: Triggers when someone sends /active
  64. async def check_active(update: Update, context: ContextTypes.DEFAULT_TYPE):
  65. if update.effective_chat.id != CHANNEL_ID:
  66. return
  67.  
  68. # 1. Capture exact execution time (in UTC)
  69. command_time = update.effective_message.date.astimezone(timezone.utc)
  70.  
  71. # Get the start of the current day (00:00:00 UTC) to handle the daily history reset
  72. start_of_day_str = command_time.strftime('%Y-%m-%d 00:00:00')
  73.  
  74. # 2. Subtract exactly 1 hour and round down minutes/seconds to :00
  75. cutoff_time = (command_time - timedelta(hours=1)).replace(minute=0, second=0, microsecond=0)
  76.  
  77. cutoff_str = cutoff_time.strftime('%H:%M:%S')
  78. command_str = command_time.strftime('%H:%M:%S')
  79. cutoff_db_format = cutoff_time.strftime('%Y-%m-%d %H:%M:%S')
  80.  
  81. # Send temporary progress indicator
  82. loading_msg = await context.bot.send_message(
  83. chat_id=CHANNEL_ID,
  84. text=f"⏳ **Filtering message data...**\nCounting qualified chats sent before {cutoff_str} UTC..."
  85. )
  86.  
  87. # 3. Clean up and execute query with daily reset constraint
  88. conn = sqlite3.connect('palaro.db')
  89. cursor = conn.cursor()
  90.  
  91. # CRITICAL: Automatically purge any chat records from previous dates (Older than today 00:00:00)
  92. cursor.execute('DELETE FROM chats WHERE datetime(timestamp) < datetime(?)', (start_of_day_str,))
  93. conn.commit()
  94.  
  95. # Query local database for users reaching >= 30 chats between 00:00:00 today and the 1-hour cutoff window
  96. cursor.execute('''
  97. SELECT user_identifier, COUNT(*)
  98. FROM chats
  99. WHERE datetime(timestamp) >= datetime(?) AND datetime(timestamp) <= datetime(?)
  100. GROUP BY user_identifier
  101. ''', (start_of_day_str, cutoff_db_format))
  102. rows = cursor.fetchall()
  103. conn.close()
  104.  
  105. # 4. Generate winners table
  106. qualified_users = []
  107. for user, count in rows:
  108. if count >= 30:
  109. qualified_users.append(f"• {user} — **{count} chats** ✅")
  110.  
  111. # 5. Format and dispatch final summary
  112. response_text = (
  113. f"🏆 **QUALIFIED USERS (30+ CHATS REQUIRED)** 🏆\n"
  114. f"━━━━━━━━━━━━━━━━━━━━\n"
  115. f"📅 **Date Today:** {command_time.strftime('%Y-%m-%d')}\n"
  116. f"⏰ **Active Command Time:** {command_str} UTC\n"
  117. f"⏱ **Cutoff Time (1hr Before):** {cutoff_str} UTC\n"
  118. f"━━━━━━━━━━━━━━━━━━━━\n\n"
  119. )
  120.  
  121. if qualified_users:
  122. response_text += "\n".join(qualified_users)
  123. else:
  124. response_text += f"❌ No users reached 30 or more chats within today's window before the cutoff."
  125.  
  126. await loading_msg.edit_text(response_text)
  127.  
  128. def main():
  129. init_db()
  130. application = Application.builder().token(TOKEN).build()
  131.  
  132. # Capture standard messages to continuous feed
  133. application.add_handler(MessageHandler(filters.Chat(CHANNEL_ID) & ~filters.COMMAND, track_messages))
  134.  
  135. # Listen to command events
  136. application.add_handler(CommandHandler("active", check_active))
  137.  
  138. print("=== [ONLINE] HTTP BOT IS TRACKING WITH AUTO-RESET RUNNING ===")
  139. application.run_polling()
  140.  
  141. if __name__ == "__main__":
  142. main()
Advertisement
Comments
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment