auto-renamer / plugins /user /start.py
dragxd's picture
Final: Restore /myusage, remove /upgrade and all plan-related codes
ef51582
from datetime import date as date_
import os, re, datetime, random, asyncio, time, humanize
from script import *
from pyrogram.errors import UserNotParticipant
from pyrogram import Client, filters, enums
from pyrogram.types import (InlineKeyboardButton, InlineKeyboardMarkup)
from helper.progress import humanbytes
from helper.database import botdata, find_one, total_user
from helper.database import insert, find_one, used_limit, usertype, uploadlimit, addpredata, total_rename, total_size
from pyrogram.file_id import FileId
from helper.database import daily as daily_
from helper.date import check_expi
from config import *
token = BOT_TOKEN
botid = token.split(':')[0]
@Client.on_message(filters.private & filters.command(["start"]))
async def start(client, message):
user_id = message.chat.id
old = insert(int(user_id))
if old != True:
try:
user = find_one(user_id)
user_plan = user.get("usertype", "Free")
await client.send_message(LOG_CHANNEL, f"<b><emoji id='5224607267797606837'>πŸ’Œ</emoji> New User Started The Bot!</b>\n\n<b>User ID :</b> <code>{user_id}</code>\n<b>First Name :</b> {message.from_user.first_name}\n<b>Last Name :</b> {message.from_user.last_name or 'None'}\n<b>User Name :</b> @{message.from_user.username or 'None'}\n<b>User Mention :</b> {message.from_user.mention}\n<b>User Link :</b> <a href='tg://openmessage?user_id={user_id}'>Click Here</a>\n<b>User Plan :</b> {user_plan}")
except Exception as e:
print(f"Logging Error: {e}")
try:
id = message.text.split(' ')[1]
except IndexError:
id = None
loading_sticker_message = await message.reply_sticker("CAACAgIAAxkBAALmzGXSSt3ppnOsSl_spnAP8wHC26jpAAJEGQACCOHZSVKp6_XqghKoHgQ")
await asyncio.sleep(2)
await loading_sticker_message.delete()
if FORCE_SUBS:
try:
user = await client.get_chat_member(FORCE_SUBS, user_id)
if user.status == enums.ChatMemberStatus.BANNED:
await message.reply_text("<b>Sorry, You Are Banned To Use Me.</b>")
return
except UserNotParticipant:
await message.reply_text(
text="""<b><emoji id="5316994101688677895">πŸ’Œ</emoji> Access Denied!</b>\n\n<i>To maintain our <b>High-Speed Renaming</b> infrastructure, we require all users to be part of our community.</i>\n\n<b><emoji id="5456140674028019486">⚑️</emoji> Kindly Join @dragbotsupport to unlock all features.</b>""",
reply_markup=InlineKeyboardMarkup([
[InlineKeyboardButton("πŸ”Ί Join Update Channel πŸ”Ί", url=f"https://t.me/{FORCE_SUBS}")]
])
)
return
text = f"""<emoji id="5224607267797606837">πŸ’Œ</emoji> <b>Welcome, {message.from_user.mention}!</b>\n\n<emoji id="5985386442824619877">πŸš€</emoji> <i>Experience the next level of <b>Auto Renaming</b> with unmatched speed and precision.</i>\n\n<b><emoji id="5433653135799228968">πŸ“</emoji> High-End Features:</b>\n β€’ <b>Renaming</b> with custom metadata.\n β€’ <b>Thumbnail</b> management with ease.\n β€’ <b>Convert</b> between Files and Videos.\n β€’ <b>Fast</b> & Secure processing.\n\n<emoji id="5377834924776627189">⚑️</emoji> <i>Built for efficiency, designed for you.</i>\n\n<b>Bot Managed By @dragbotsupport</b>"""
buttons = [
[InlineKeyboardButton("Updates", url="https://t.me/dragbots", icon_custom_emoji_id=5443038326535759644),
InlineKeyboardButton("Support", url="https://t.me/dragbotsupport", icon_custom_emoji_id=5462921117423384478)],
[InlineKeyboardButton("Help", callback_data='help', icon_custom_emoji_id=5375074927252621134),
InlineKeyboardButton("About", callback_data='about', icon_custom_emoji_id=5224607267797606837)],
[InlineKeyboardButton("Stats", callback_data="stats", icon_custom_emoji_id=5042290883949495533)],
[InlineKeyboardButton("Developer", url="https://t.me/lungiiman", icon_custom_emoji_id=5150078684585002132)]
]
await message.reply_photo(
photo=START_PIC,
caption=text,
reply_markup=InlineKeyboardMarkup(buttons),
quote=True
)
return
@Client.on_message((filters.private & (filters.document | filters.audio | filters.video)) | filters.channel & (filters.document | filters.audio | filters.video))
async def send_doc(client, message):
user_id = message.chat.id
old = insert(int(user_id))
user_id = message.from_user.id
if FORCE_SUBS:
try:
await client.get_chat_member(FORCE_SUBS, user_id)
except UserNotParticipant:
_newus = find_one(message.from_user.id)
user = _newus["usertype"]
await message.reply_text("<b>Hello Dear \n\nYou Need To Join In My Channel To Use Me\n\nKindly Please Join Channel</b>",
reply_to_message_id=message.id,
reply_markup=InlineKeyboardMarkup([
[InlineKeyboardButton("πŸ”Ί Update Channel πŸ”Ί", url=f"https://t.me/{FORCE_SUBS}")]
]))
await client.send_message(LOG_CHANNEL, f"<b><u>New User Started The Bot</u></b> \n\n<b>User ID :</b> <code>{user_id}</code> \n<b>First Name :</b> {message.from_user.first_name} \n<b>Last Name :</b> {message.from_user.last_name} \n<b>User Name :</b> @{message.from_user.username} \n<b>User Mention :</b> {message.from_user.mention} \n<b>User Link :</b> <a href='tg://openmessage?user_id={user_id}'>Click Here</a> \n<b>User Plan :</b> {user}")
return
botdata(int(botid))
user_deta = find_one(user_id)
daily = user_deta.get("daily", 0)
c_time = time.time()
LIMIT = 10 # Standard limit or remove if not needed, keeping it simple for now
used_date = user_deta.get("date", 0)
then = used_date + LIMIT
left = round(then - c_time)
conversion = datetime.timedelta(seconds=left)
ltime = str(conversion)
if left > 0:
await message.reply_text(f"<b>Sorry Dude I Am Not Only For You \n\nFlood Control Is Active So Please Wait For {ltime} </b>", reply_to_message_id=message.id)
else:
# Forward a single message
media = await client.get_messages(message.chat.id, message.id)
file = media.document or media.video or media.audio
dcid = FileId.decode(file.file_id).dc_id
filename = file.file_name
file_id = file.file_id
used_ = find_one(message.from_user.id)
used = used_.get("used_limit", 0)
limit = used_.get("uploadlimit", 5368709120) # Default to 5GB or similar
expi = daily - int(time.mktime(time.strptime(str(date_.today()), '%Y-%m-%d')))
if expi != 0:
today = date_.today()
pattern = '%Y-%m-%d'
epcho = int(time.mktime(time.strptime(str(today), pattern)))
daily_(message.from_user.id, epcho)
used_limit(message.from_user.id, 0)
used = 0
remain = limit - used
if remain < int(file.file_size):
await message.reply_text(f"100% Of Daily {humanbytes(limit)} Data Quota Exhausted.\n\n<b>File Size Detected :</b> {humanbytes(file.file_size)}\n<b>Used Daily Limit :</b> {humanbytes(used)}\n\nYou Have Only <b>{humanbytes(remain)}</b> Left On Your Account.")
return
filesize = humanize.naturalsize(file.file_size)
await message.reply_text(f"""__What Do You Want Me To Do With This File ?__\n\n**File Name :** `{filename}`\n**File Size :** {filesize}\n**DC ID :** {dcid}""", reply_to_message_id=message.id, reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("Rename", callback_data="rename", icon_custom_emoji_id=5985386442824619877),
InlineKeyboardButton("Set Caption", callback_data="instant_caption", icon_custom_emoji_id=5316994101688677895)],
[InlineKeyboardButton("Cancel", callback_data="cancel")]]))