Repository navigation
Expand file tree
/
Copy pathbot.py
More file actions
193 lines (171 loc) · 9.73 KB
/
Copy pathbot.py
File metadata and controls
193 lines (171 loc) · 9.73 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
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
try: # faster event loop (must be installed before pyrogram is imported)
import uvloop
uvloop.install()
except Exception:
pass
import aiohttp, asyncio, warnings, pytz, datetime
import logging
import logging.config
import glob, sys
import importlib.util
from pathlib import Path
from pyrogram import Client, __version__, errors
from pyrogram.raw.all import layer
from pyrogram import idle
from pyrogram.types import BotCommand, BotCommandScopeDefault, BotCommandScopeAllPrivateChats
from config import Config
from helper import ui # noqa: F401 (small caps + coloured buttons, must load before plugins)
from helper.smallcaps import sc
from plugins.web_support import web_server
from plugins.file_rename import app
from helper.fast_mtproto import enable_fast_mtproto
from helper.database import unrated_coder
from helper.premium_check import get_session_info, describe
from helper.watchdog import start_watchdog
import os
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
handlers=[logging.FileHandler('BotLog.txt'),
logging.StreamHandler()]
)
logging.getLogger("pyrogram").setLevel(logging.WARNING)
# Enable hardware crypto + multi-session parallel MTProto socket pool
enable_fast_mtproto()
class AdvRenameBot(Client):
def __init__(self):
super().__init__(
name="Adv-RenameBot",
api_id=Config.API_ID,
api_hash=Config.API_HASH,
bot_token=Config.BOT_TOKEN,
workers=256,
plugins={"root": "plugins"},
sleep_threshold=Config.BOT_SLEEP_THRESHOLD,
max_concurrent_transmissions=Config.MAX_CONCURRENT_TRANSMISSIONS,
max_message_cache_size=Config.MAX_MESSAGE_CACHE_SIZE
# max_topic_cache_size hata diya gaya hai compatibility ke liye
)
async def start(self):
await super().start()
try:
from helper.looplag import start as _looplag
_looplag(asyncio.get_running_loop())
except Exception:
pass
me = await self.get_me()
self.mention = me.mention
self.username = me.username
self.uptime = Config.BOT_UPTIME
bot_settings = await unrated_coder.get_bot_settings()
self.premium = bot_settings.get('premium_mode', Config.PREMIUM_MODE)
self.parallel_task_limit = bot_settings.get('parallel_task_limit', 1)
self.queue_mode = bot_settings.get('queue_mode', True)
self.queue_task_limit = bot_settings.get('queue_task_limit', 5)
self.restart_broadcast_mode = bot_settings.get('restart_broadcast_mode', True)
self.max_file_size = bot_settings.get('max_file_size', '2GB')
self.uploadlimit = Config.UPLOAD_LIMIT_MODE
Config.BOT = self
# Set by helper.watchdog before a self-restart: no notifications at all.
silent_restart = os.environ.pop("SILENT_RESTART", "") == "1"
app = aiohttp.web.AppRunner(await web_server())
await app.setup()
bind_address = "0.0.0.0"
await aiohttp.web.TCPSite(app, bind_address, Config.PORT).start()
print(f"{me.first_name} Iꜱ Sᴛᴀʀᴛᴇᴅ.....✨️")
try:
commands = [
BotCommand("start", sc("⚡ sᴛᴀʀᴛ ᴛʜᴇ ʙᴏᴛ")),
BotCommand("help", sc("❓ ɢᴇᴛ ʜᴇʟᴘ ᴍᴇssᴀɢᴇ")),
BotCommand("myplan", sc("👤 ᴠɪᴇᴡ ʏᴏᴜʀ ᴘʟᴀɴ")),
BotCommand("plans", sc("💳 ᴠɪᴇᴡ ᴘʀᴇᴍɪᴜᴍ ᴘʟᴀɴs")),
BotCommand("metadata", sc("📝 ᴄᴏɴғɪɢᴜʀᴇ ᴍᴇᴛᴀᴅᴀᴛᴀ sᴇᴛᴛɪɴɢs")),
BotCommand("set_caption", sc("✏️ sᴇᴛ ᴄᴜsᴛᴏᴍ ᴄᴀᴘᴛɪᴏɴ")),
BotCommand("see_caption", sc("👁️ sᴇᴇ ᴄᴜʀʀᴇɴᴛ ᴄᴀᴘᴛɪᴏɴ")),
BotCommand("del_caption", sc("🗑️ ᴅᴇʟᴇᴛᴇ ᴄᴜsᴛᴏᴍ ᴄᴀᴘᴛɪᴏɴ")),
BotCommand("view_thumb", sc("🖼️ ᴠɪᴇᴡ ᴄᴜsᴛᴏᴍ ᴛʜᴜᴍʙɴᴀɪʟ")),
BotCommand("del_thumb", sc("🗑️ ᴅᴇʟᴇᴛᴇ ᴄᴜsᴛᴏᴍ ᴛʜᴜᴍʙɴᴀɪʟ")),
BotCommand("set_prefix", sc("🔤 sᴇᴛ ᴄᴜsᴛᴏᴍ ᴘʀᴇғɪx")),
BotCommand("see_prefix", sc("👁️ sᴇᴇ ᴄᴜʀʀᴇɴᴛ ᴘʀᴇғɪx")),
BotCommand("del_prefix", sc("❌ ᴅᴇʟᴇᴛᴇ ᴄᴜsᴛᴏᴍ ᴘʀᴇғɪx")),
BotCommand("set_suffix", sc("🔤 sᴇᴛ ᴄᴜsᴛᴏᴍ sᴜғғɪx")),
BotCommand("see_suffix", sc("👁️ sᴇᴇ ᴄᴜʀʀᴇɴᴛ sᴜғғɪx")),
BotCommand("del_suffix", sc("❌ ᴅᴇʟᴇᴛᴇ ᴄᴜsᴛᴏᴍ sᴜғғɪx")),
BotCommand("settings", sc("⚙️ ᴄᴏɴғɪɢᴜʀᴇ ʙᴏᴛ sᴇᴛᴛɪɴɢs (ᴀᴅᴍɪɴs)")),
BotCommand("stats", sc("📊 ᴠɪᴇᴡ ʙᴏᴛ sᴛᴀᴛs (ᴀᴅᴍɪɴs)")),
BotCommand("restart", sc("🔄 ʀᴇsᴛᴀʀᴛ ᴛʜᴇ ʙᴏᴛ (ᴀᴅᴍɪɴs)")),
BotCommand("logs", sc("📜 ᴠɪᴇᴡ ʙᴏᴛ ʟᴏɢs (ᴀᴅᴍɪɴs)")),
BotCommand("addpremium", sc("➕ ᴀᴅᴅ ᴘʀᴇᴍɪᴜᴍ ᴜsᴇʀ (ᴀᴅᴍɪɴs)")),
BotCommand("removepremium", sc("➖ ʀᴇᴍᴏᴠᴇ ᴘʀᴇᴍɪᴜᴍ ᴜsᴇʀ (ᴀᴅmins)")),
BotCommand("ban", sc("🚫 ʙᴀɴ ᴀ ᴜsᴇʀ (ᴀᴅᴍɪɴs)")),
BotCommand("unban", sc("✅ ᴜɴʙᴀɴ ᴀ ᴜsᴇʀ (ᴀᴅᴍɪɴs)")),
BotCommand("banned_users", sc("📋 ᴠɪᴇᴡ ʙᴀɴɴᴇᴅ ᴜsᴇʀs (ᴀᴅᴍɪɴs)")),
BotCommand("broadcast", sc("📢 ʙʀᴏᴀᴅᴄᴀsᴛ ᴍᴇssᴀɢᴇ (ᴀᴅᴍɪɴs)")),
]
res1 = await self.set_bot_commands(commands, scope=BotCommandScopeDefault())
res2 = await self.set_bot_commands(commands, scope=BotCommandScopeAllPrivateChats())
logging.info(f"Set bot commands result default: {res1}, private: {res2}")
print("Bᴏᴛ Cᴏᴍᴍᴀɴᴅs Sᴇᴛ Sᴜᴄᴄᴇssғᴜʟʟʏ! ✨")
except Exception as e:
logging.error(f"Error setting bot commands: {e}", exc_info=True)
print(f"Eʀʀᴏʀ sᴇᴛᴛɪɴɢ ʙᴏᴛ ᴄᴏᴍᴍᴀɴᴅs: {e}")
for id in ([] if silent_restart else Config.ADMIN):
if Config.STRING_SESSION:
try: await self.send_message(id, f"🚀 <b><u>𝐵𝑜𝑡 𝑆𝑡𝑎𝑟𝑡𝑒𝑑 —</u></b>\n<blockquote>⚡ <b>2GB+ File Support Enabled!</b>\n\n📌 <b>Note:</b> Telegram Premium Account String Session configured for 2GB+ files support.\n\n✨ <b>{me.first_name} is Now Online & Ready!</b></blockquote>")
except: pass
else:
try: await self.send_message(id, f"🚀 <b><u>𝐵𝑜𝑡 𝑆𝑡𝑎𝑟𝑡𝑒𝑑 —</u></b>\n<blockquote>⚡ <b>2GB- File Support Enabled!</b>\n\n✨ <b>{me.first_name} is Now Online & Ready!</b></blockquote>")
except: pass
if Config.LOG_CHANNEL and not silent_restart:
try:
curr = datetime.datetime.now(pytz.timezone("Asia/Kolkata"))
date = curr.strftime('%d %B, %Y')
time = curr.strftime('%I:%M:%S %p')
await self.send_message(Config.LOG_CHANNEL, f"**__{me.mention} Iꜱ Rᴇsᴛᴀʀᴛᴇᴅ !!**\n\n📅 Dᴀᴛᴇ : `{date}`\n⏰ Tɪᴍᴇ : `{time}`\n🌐 Tɪᴍᴇᴢᴏɴᴇ : `Asia/Kolkata`\n\n🉐 Vᴇʀsɪᴏɴ : `v{__version__} (Layer {layer})`</b>")
except:
print("Pʟᴇᴀꜱᴇ Mᴀᴋᴇ Tʜɪꜱ Iꜱ Aᴅᴍɪɴ Iɴ Yᴏᴜʀ Lᴏɢ Cʜᴀɴɴᴇʟ")
async def stop(self, *args):
for id in Config.ADMIN:
try: await self.send_message(id, f"**Bot Stopped....**")
except: pass
print("Bot Stopped 🙄")
await super().stop()
digital_instance = AdvRenameBot()
def main():
async def start_services():
if Config.STRING_SESSION:
await asyncio.gather(app.start(), digital_instance.start())
try:
info = await get_session_info(app)
logging.info(f"STRING_SESSION account: {describe(info)} | premium={info['premium']} (via {info['source']})")
if not info["premium"]:
logging.warning(
f"STRING_SESSION account {describe(info)} does not have an active Telegram "
"Premium subscription - 2GB+/4GB uploads will stay disabled. "
"Make sure the session was generated from the account that bought Premium."
)
except Exception as e:
logging.error(f"Could not verify STRING_SESSION premium status: {e}")
else:
await asyncio.gather(digital_instance.start())
start_watchdog()
await idle()
if Config.STRING_SESSION:
await asyncio.gather(app.stop(), digital_instance.stop())
else:
await asyncio.gather(digital_instance.stop())
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(start_services())
except KeyboardInterrupt:
print("\n🛑 Bot stopped by user!")
finally:
loop.close()
if __name__ == "__main__":
warnings.filterwarnings("ignore", message="There is no current event loop")
try:
main()
except errors.FloodWait as ft:
print(f"⏳ FloodWait: Sleeping for {ft.value} seconds")
asyncio.run(asyncio.sleep(ft.value))
print("Now Ready For Deploying!")
main()