-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
55 lines (45 loc) · 1.95 KB
/
Copy pathbot.py
File metadata and controls
55 lines (45 loc) · 1.95 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
import time
from telegram import Update, Bot
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
# ====== CONFIG ======
BOT_TOKEN = "8046747342:AAFQ1a523b8WltQwDFwH6PuL7MV1lFdMrkU"
OWNER_IDS = [7851997598, 7788135096, 7383542259] # Owner IDs
GROUP_ID = -1002662393368 # Test group ID
# Store active passwords
active_passwords = {} # password: expiry_time
# ====== COMMANDS ======
async def genpass(update: Update, context: ContextTypes.DEFAULT_TYPE):
user_id = update.effective_user.id
if user_id not in OWNER_IDS:
await update.message.reply_text("❌ You are not authorized to generate passwords!")
return
try:
password = context.args[0]
if context.args[1] != "validity":
await update.message.reply_text("❌ Usage: /genpass <password> validity <time_in_seconds>")
return
validity = int(context.args[2])
except (IndexError, ValueError):
await update.message.reply_text("❌ Usage: /genpass <password> validity <time_in_seconds>")
return
expiry_time = time.time() + validity
active_passwords[password] = expiry_time
await context.bot.send_message(
chat_id=GROUP_ID,
text=f"🔑 New Activation Password:\n`{password}`\n⏱ Valid for: {validity} seconds",
parse_mode="Markdown"
)
await update.message.reply_text(f"✅ Password `{password}` generated for {validity} seconds and sent to group.")
# Check expired passwords periodically
async def check_expired(context: ContextTypes.DEFAULT_TYPE):
now = time.time()
expired = [p for p, t in active_passwords.items() if t < now]
for p in expired:
del active_passwords[p]
# ====== BOT SETUP ======
app = ApplicationBuilder().token(BOT_TOKEN).build()
app.add_handler(CommandHandler("genpass", genpass))
# Job to clean expired passwords every 10 seconds
app.job_queue.run_repeating(check_expired, interval=10, first=10)
print("Bot is running...")
app.run_polling()