-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathadmin_panel.py
More file actions
105 lines (90 loc) · 4.11 KB
/
admin_panel.py
File metadata and controls
105 lines (90 loc) · 4.11 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
from config import Config, Txt
from helper.database import madflixbotz
from pyrogram.types import Message
from pyrogram import Client, filters
from pyrogram.errors import FloodWait, InputUserDeactivated, UserIsBlocked, PeerIdInvalid
import os, sys, time, asyncio, logging, datetime
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
ADMIN_USER_ID = Config.ADMIN
# Flag to indicate if the bot is restarting
is_restarting = False
@Client.on_message(filters.private & filters.command("restart") & filters.user(ADMIN_USER_ID))
async def restart_bot(b, m):
global is_restarting
if not is_restarting:
is_restarting = True
await m.reply_text("**🔄 Restarting.....**")
# Gracefully stop the bot's event loop
b.stop()
time.sleep(2) # Adjust the delay duration based on your bot's shutdown time
# Restart the bot process
os.execl(sys.executable, sys.executable, *sys.argv)
@Client.on_message(filters.private & filters.command(["tutorial"]))
async def tutorial(bot,message):
user_id = message.from_user.id
format_template = await madflixbotz.get_format_template(user_id)
await message.reply_text(
text =Txt.FILE_NAME_TXT.format(format_template=format_template),
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup([
[InlineKeyboardButton("🦋 Admin",url = "https://t.me/teamotaku109"),
InlineKeyboardButton("⚡ Tutorial",url = "https://t.me/animeotaku109") ]])
)
@Client.on_message(filters.command(["stats", "status"]) & filters.user(Config.ADMIN))
async def get_stats(bot, message):
total_users = await madflixbotz.total_users_count()
uptime = time.strftime("%Hh%Mm%Ss", time.gmtime(time.time() - bot.uptime))
start_t = time.time()
st = await message.reply('**Accessing The Details.....**')
end_t = time.time()
time_taken_s = (end_t - start_t) * 1000
await st.edit(text=f"**--Bot Status--** \n\n**⌚️ Bot Uptime :** {uptime} \n**🐌 Current Ping :** `{time_taken_s:.3f} ms` \n**👭 Total Users :** `{total_users}`")
@Client.on_message(filters.command("broadcast") & filters.user(Config.ADMIN) & filters.reply)
async def broadcast_handler(bot: Client, m: Message):
await bot.send_message(Config.LOG_CHANNEL, f"{m.from_user.mention} or {m.from_user.id} Is Started The Broadcast......")
all_users = await madflixbotz.get_all_users()
broadcast_msg = m.reply_to_message
sts_msg = await m.reply_text("Broadcast Started..!")
done = 0
failed = 0
success = 0
start_time = time.time()
total_users = await madflixbotz.total_users_count()
async for user in all_users:
sts = await send_msg(user['_id'], broadcast_msg)
if sts == 200:
success += 1
else:
failed += 1
if sts == 400:
await madflixbotz.delete_user(user['_id'])
done += 1
if not done % 20:
await sts_msg.edit(f"Broadcast In Progress: \n\nTotal Users {total_users} \nCompleted : {done} / {total_users}\nSuccess : {success}\nFailed : {failed}")
completed_in = datetime.timedelta(seconds=int(time.time() - start_time))
await sts_msg.edit(f"Bʀᴏᴀᴅᴄᴀꜱᴛ Cᴏᴍᴩʟᴇᴛᴇᴅ: \nCᴏᴍᴩʟᴇᴛᴇᴅ Iɴ `{completed_in}`.\n\nTotal Users {total_users}\nCompleted: {done} / {total_users}\nSuccess: {success}\nFailed: {failed}")
async def send_msg(user_id, message):
try:
await message.copy(chat_id=int(user_id))
return 200
except FloodWait as e:
await asyncio.sleep(e.value)
return send_msg(user_id, message)
except InputUserDeactivated:
logger.info(f"{user_id} : Deactivated")
return 400
except UserIsBlocked:
logger.info(f"{user_id} : Blocked The Bot")
return 400
except PeerIdInvalid:
logger.info(f"{user_id} : User ID Invalid")
return 400
except Exception as e:
logger.error(f"{user_id} : {e}")
return 500
# Jishu Developer
# Don't Remove Credit 🥺
# Telegram Channel @Madflix_Bots
# Developer @JishuDeveloper