This repository was archived by the owner on May 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbot.py
More file actions
323 lines (282 loc) · 15.2 KB
/
bot.py
File metadata and controls
323 lines (282 loc) · 15.2 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
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
# ═══════════════════════════════════════════════════════════════
# 𝕽𝕺𝕏𝖄•𝔹𝕒𝕤𝕚𝕔ℕ𝕖𝕖𝕕𝔹𝕠𝕥 ⚡️
# Created by: RoxyBasicNeedBot
# GitHub: https://github.com/RoxyBasicNeedBot
# Telegram: https://t.me/roxybasicneedbot1
# Website: https://roxybasicneedbot.unaux.com/?i=1
# YouTube: @roxybasicneedbot
#
# Portfolio: https://aratt.ai/@roxybasicneedbot
#
# Bot & Website Developer 🤖
# Creator of RoxyBasicNeedBot & many automation tools ⚡
# Skilled in Python, APIs, and Web Development
#
# © 2026 RoxyBasicNeedBot. All Rights Reserved.
# ═══════════════════════════════════════════════════════════════
# extra imports
import aiohttp, asyncio, warnings, pytz, datetime
import logging
import logging.config
import glob, sys
import importlib.util
from pathlib import Path
# pyrogram imports
from pyrogram import Client, __version__, errors
from pyrogram.raw.all import layer
from pyrogram import idle
# bots imports
from config import Config
from plugins.web_support import web_server
from plugins.file_rename import app
# Get logging configurations
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
handlers=[logging.FileHandler('BotLog.txt'),
logging.StreamHandler()]
)
#logger = logging.getLogger(__name__)
logging.getLogger("pyrofork").setLevel(logging.WARNING)
logging.getLogger("hachoir").setLevel(logging.ERROR) # Suppress hachoir warnings
logging.getLogger("hachoir.parser").setLevel(logging.ERROR)
class RoxyRenameBot(Client):
def __init__(self):
super().__init__(
name="RoxyRenameBot",
api_id=Config.API_ID,
api_hash=Config.API_HASH,
bot_token=Config.BOT_TOKEN,
workers=200,
plugins={"root": "plugins"},
sleep_threshold=5,
max_concurrent_transmissions=50
)
async def start(self):
await super().start()
me = await self.get_me()
self.mention = me.mention
self.username = me.username
self.uptime = Config.BOT_UPTIME
self.premium = Config.PREMIUM_MODE
self.uploadlimit = Config.UPLOAD_LIMIT_MODE
Config.BOT = self
# Set bot commands in Telegram menu
await self.register_bot_commands()
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()
path = "plugins/*.py"
files = glob.glob(path)
for name in files:
with open(name) as a:
patt = Path(a.name)
plugin_name = patt.stem.replace(".py", "")
plugins_path = Path(f"plugins/{plugin_name}.py")
import_path = "plugins.{}".format(plugin_name)
spec = importlib.util.spec_from_file_location(import_path, plugins_path)
load = importlib.util.module_from_spec(spec)
spec.loader.exec_module(load)
sys.modules["plugins" + plugin_name] = load
print("Roxy Bot Imported " + plugin_name)
print(f"{me.first_name} Iꜱ Sᴛᴀʀᴛᴇᴅ.....✨️")
# Start auto-delete background scheduler
asyncio.create_task(self.auto_delete_scheduler())
print("🗑️ Auto-delete scheduler started")
for id in Config.ADMIN:
if Config.STRING_SESSION:
try: await self.send_message(id, f"𝟮𝗚𝗕+ ғɪʟᴇ sᴜᴘᴘᴏʀᴛ ʜᴀs ʙᴇᴇɴ ᴀᴅᴅᴇᴅ ᴛᴏ ʏᴏᴜʀ ʙᴏᴛ.\n\nNote: 𝐓𝐞𝐥𝐞𝐠𝐫𝐚𝐦 𝐩𝐫𝐞𝐦𝐢𝐮𝐦 𝐚𝐜𝐜𝐨𝐮𝐧𝐭 𝐬𝐭𝐫𝐢𝐧𝐠 𝐬𝐞𝐬𝐬𝐢𝐨𝐧 𝐫𝐞𝐪𝐮𝐢𝐫𝐞𝐝 𝐓𝐡𝐞𝐧 𝐬𝐮𝐩𝐩𝐨𝐫𝐭𝐬 𝟐𝐆𝐁+ 𝐟𝐢𝐥𝐞𝐬.\n\n**__{me.first_name} Iꜱ Sᴛᴀʀᴛᴇᴅ.....✨️__**")
except: pass
else:
try: await self.send_message(id, f"𝟮𝗚𝗕- ғɪʟᴇ sᴜᴘᴘᴏʀᴛ ʜᴀs ʙᴇᴇɴ ᴀᴅᴅᴇᴅ ᴛᴏ ʏᴏᴜʀ ʙᴏᴛ.\n\n**__{me.first_name} Iꜱ Sᴛᴀʀᴛᴇᴅ.....✨️__**")
except: pass
if Config.LOG_CHANNEL:
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 register_bot_commands(self):
"""Register bot commands with Telegram for the menu"""
from pyrogram.types import BotCommand, BotCommandScopeAllPrivateChats, BotCommandScopeChat
# Commands visible to all users in private chats
user_commands = [
BotCommand("start", "🚀 Sᴛᴀʀᴛ ᴛʜᴇ ʙᴏᴛ"),
BotCommand("free", "💕 Fʀᴇᴇ ꜰᴏʀ 30 ᴅᴀʏs ᴡɪᴛʜ ʟᴏᴠᴇ"),
BotCommand("set_watermark", "🎨 Sᴇᴛ ᴠɪᴅᴇᴏ ᴡᴀᴛᴇʀᴍᴀʀᴋ"),
BotCommand("see_watermark", "👁️ Vɪᴇᴡ ᴡᴀᴛᴇʀᴍᴀʀᴋ"),
BotCommand("del_watermark", "🗑️ Dᴇʟᴇᴛᴇ ᴡᴀᴛᴇʀᴍᴀʀᴋ"),
BotCommand("extract_audio", "🎵 Exᴛʀᴀᴄᴛ ᴀᴜᴅɪᴏ ꜰʀᴏᴍ ᴠɪᴅᴇᴏ"),
BotCommand("features", "✨ Aʟʟ Bᴏᴛ Fᴇᴀᴛᴜʀᴇs"),
BotCommand("settings", "⚙️ Bᴏᴛ sᴇᴛᴛɪɴɢs"),
BotCommand("stop", "🛑 Sᴛᴏᴘ ᴄᴜʀʀᴇɴᴛ ᴏᴘᴇʀᴀᴛɪᴏɴ"),
BotCommand("myplan", "📊 Cʜᴇᴄᴋ ʏᴏᴜʀ ᴘʟᴀɴ"),
BotCommand("plans", "💸 Vɪᴇᴡ ᴘʀᴇᴍɪᴜᴍ ᴘʟᴀɴs"),
BotCommand("merge", "🎬 Sᴛᴀʀᴛ ᴠɪᴅᴇᴏ ᴍᴇʀɢᴇ ᴍᴏᴅᴇ"),
BotCommand("mergeall", "🔗 Mᴇʀɢᴇ ᴀʟʟ ǫᴜᴇᴜᴇᴅ ᴠɪᴅᴇᴏs"),
BotCommand("mergestatus", "📋 Vɪᴇᴡ ᴍᴇʀɢᴇ ǫᴜᴇᴜᴇ"),
BotCommand("clearmerge", "🗑️ Cʟᴇᴀʀ ᴍᴇʀɢᴇ ǫᴜᴇᴜᴇ"),
BotCommand("exitmerge", "🚪 Exɪᴛ ᴍᴇʀɢᴇ ᴍᴏᴅᴇ"),
BotCommand("autorename", "📝 Sᴇᴛ ᴀᴜᴛᴏ ʀᴇɴᴀᴍᴇ"),
BotCommand("see_autorename", "🔎 Vɪᴇᴡ ᴀᴜᴛᴏʀᴇɴᴀᴍᴇ"),
BotCommand("del_autorename", "🗑️ Dᴇʟᴇᴛᴇ ᴀᴜᴛᴏʀᴇɴᴀᴍᴇ"),
BotCommand("setmedia", "🎬 Sᴇᴛ ᴍᴇᴅɪᴀ ᴛʏᴘᴇ"),
BotCommand("delmedia", "📤 Dᴇʟᴇᴛᴇ ᴍᴇᴅɪᴀ ᴛʏᴘᴇ"),
BotCommand("set_caption", "📝 Sᴇᴛ ᴄᴜsᴛᴏᴍ ᴄᴀᴘᴛɪᴏɴ"),
BotCommand("see_caption", "📋 Vɪᴇᴡ ʏᴏᴜʀ ᴄᴀᴘᴛɪᴏɴ"),
BotCommand("del_caption", "🧹 Dᴇʟᴇᴛᴇ ᴄᴀᴘᴛɪᴏɴ"),
BotCommand("set_prefix", "✏️ Sᴇᴛ ғɪʟᴇɴᴀᴍᴇ ᴘʀᴇғɪx"),
BotCommand("see_prefix", "📄 Vɪᴇᴡ ʏᴏᴜʀ ᴘʀᴇғɪx"),
BotCommand("del_prefix", "🚮 Dᴇʟᴇᴛᴇ ᴘʀᴇғɪx"),
BotCommand("set_suffix", "🔖 Sᴇᴛ ғɪʟᴇɴᴀᴍᴇ sᴜғғɪx"),
BotCommand("see_suffix", "📑 Vɪᴇᴡ ʏᴏᴜʀ sᴜғғɪx"),
BotCommand("del_suffix", "♻️ Dᴇʟᴇᴛᴇ sᴜғғɪx"),
BotCommand("view_thumb", "🖼️ Vɪᴇᴡ ᴛʜᴜᴍʙɴᴀɪʟ"),
BotCommand("del_thumb", "🗑️ Dᴇʟᴇᴛᴇ ᴛʜᴜᴍʙɴᴀɪʟ"),
]
# ═══════════════════════════════════════════════════════════════
# 𝕽𝕺𝕏𝖄•𝔹𝕒𝕤𝕚𝕔ℕ𝕖𝕖𝕕𝔹𝕠𝕥 ⚡️
# Created by: RoxyBasicNeedBot
# GitHub: https://github.com/RoxyBasicNeedBot
# Telegram: https://t.me/roxybasicneedbot1
# Website: https://roxybasicneedbot.unaux.com/?i=1
# YouTube: @roxybasicneedbot
#
# Portfolio: https://aratt.ai/@roxybasicneedbot
#
# Bot & Website Developer 🤖
# Creator of RoxyBasicNeedBot & many automation tools ⚡
# Skilled in Python, APIs, and Web Development
#
# © 2026 RoxyBasicNeedBot. All Rights Reserved.
# ═══════════════════════════════════════════════════════════════
# Additional commands for admins
admin_commands = user_commands + [
BotCommand("broadcast", "📢 Broadcast message to all users"),
BotCommand("stats", "📊 View bot statistics"),
BotCommand("use", "📊 Tᴏᴘ 10 ᴜᴘʟᴏᴀᴅᴇʀs (24ʜʀ)"),
BotCommand("current", "👁️ Aᴄᴛɪᴠᴇ ᴜsᴇʀs ɴᴏᴡ"),
BotCommand("ban", "🚫 Ban a user"),
BotCommand("unban", "✅ Unban a user"),
BotCommand("add_premium", "💎 Add premium to user"),
BotCommand("remove_premium", "❌ Remove premium from user"),
BotCommand("premium_list", "📋 List all premium users"),
BotCommand("banned_users", "📋 List all banned users"),
BotCommand("on_maintenance", "🔧 Eɴᴀʙʟᴇ ᴍᴀɪɴᴛᴇɴᴀɴᴄᴇ ᴍᴏᴅᴇ"),
BotCommand("off_maintenance", "✅ Dɪsᴀʙʟᴇ ᴍᴀɪɴᴛᴇɴᴀɴᴄᴇ ᴍᴏᴅᴇ"),
BotCommand("forcestop", "🛑 Sᴛᴏᴘ ᴀʟʟ ᴘʀᴏᴄᴇssᴇs"),
]
try:
# Register commands with AllPrivateChats scope (using Client.set_bot_commands)
await Client.set_bot_commands(
self,
commands=user_commands,
scope=BotCommandScopeAllPrivateChats()
)
print("✅ User commands registered for all private chats")
# Set admin commands for each admin
for admin_id in Config.ADMIN:
try:
await Client.set_bot_commands(
self,
commands=admin_commands,
scope=BotCommandScopeChat(chat_id=admin_id)
)
print(f"✅ Admin commands registered for user {admin_id}")
except Exception as e:
print(f"⚠️ Could not set admin commands for {admin_id}: {e}")
except Exception as e:
print(f"❌ Error setting bot commands: {e}")
async def auto_delete_scheduler(self):
"""Background task: delete scheduled messages every 5 minutes"""
from helper.database import roxy_bot
while True:
try:
pending = await roxy_bot.get_pending_deletions()
deleted_count = 0
async for record in pending:
try:
await self.delete_messages(
record['chat_id'],
record['message_id']
)
deleted_count += 1
except Exception:
pass # Message already deleted or expired
# Always remove the record after attempting
await roxy_bot.remove_scheduled_deletion(
record['chat_id'],
record['message_id']
)
# Cleanup expired records (older than 48hr Telegram limit)
await roxy_bot.cleanup_expired_deletions()
if deleted_count > 0:
print(f"🗑️ Auto-deleted {deleted_count} message(s)")
except Exception as e:
print(f"Auto-delete scheduler error: {e}")
await asyncio.sleep(300) # Check every 5 minutes
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()
roxy_instance = RoxyRenameBot()
def main():
async def start_services():
if Config.STRING_SESSION:
try:
await asyncio.gather(app.start(), roxy_instance.start())
except Exception as e:
print(f"⚠️ Error starting Premium Client: {e}")
print("⚠️ Falling back to Standard Bot mode (No Premium features)")
Config.STRING_SESSION = None # Disable premium mode
# Ensure roxy_instance is started if it wasn't already
if not roxy_instance.is_connected:
await roxy_instance.start()
else:
await asyncio.gather(roxy_instance.start())
# Idle mode start karo
await idle()
# Bot stop karo
if Config.STRING_SESSION:
try:
await asyncio.gather(app.stop(), roxy_instance.stop())
except:
await roxy_instance.stop()
else:
await asyncio.gather(roxy_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()
# ═══════════════════════════════════════════════════════════════
# 𝕽𝕺𝕏𝖄•𝔹𝕒𝕤𝕚𝕔ℕ𝕖𝕖𝕕𝔹𝕠𝕥 ⚡️
# Created by: RoxyBasicNeedBot
# GitHub: https://github.com/RoxyBasicNeedBot
# Telegram: https://t.me/roxybasicneedbot1
# Website: https://roxybasicneedbot.unaux.com/?i=1
# YouTube: @roxybasicneedbot
#
# Portfolio: https://aratt.ai/@roxybasicneedbot
#
# Bot & Website Developer 🤖
# Creator of RoxyBasicNeedBot & many automation tools ⚡
# Skilled in Python, APIs, and Web Development
#
# © 2026 RoxyBasicNeedBot. All Rights Reserved.
# ═══════════════════════════════════════════════════════════════