|
1 | | -import os, sys |
| 1 | +# (c) @RknDeveloperr |
| 2 | +# Rkn Developer |
| 3 | +# Don't Remove Credit 😔 |
| 4 | +# Telegram Channel @RknDeveloper & @Rkn_Botz |
| 5 | +# Developer @RknDeveloperr |
| 6 | +# Special Thanks To (https://github.com/JayMahakal98) |
| 7 | +# Update Channel @Digital_Botz & @DigitalBotz_Support |
| 8 | + |
| 9 | +""" |
| 10 | +Apache License 2.0 |
| 11 | +Copyright (c) 2022 @RknDeveloper |
| 12 | +
|
| 13 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 14 | +of this software and associated documentation files (the "Software"), to deal |
| 15 | +in the Software without restriction, including without limitation the rights |
| 16 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 17 | +copies of the Software, and to permit persons to whom the Software is |
| 18 | +furnished to do so, subject to the following conditions: |
| 19 | +The above copyright notice and this permission notice shall be included in all |
| 20 | +copies or substantial portions of the Software. |
| 21 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 27 | +
|
| 28 | +Telegram Link : https://t.me/RknDeveloper |
| 29 | +Repo Link : https://github.com/RknDeveloper/Rkn_Auto-Request-Approve-bot |
| 30 | +License Link : https://github.com/RknDeveloper/Rkn_Auto-Request-Approve-bot/blob/main/LICENSE |
| 31 | +""" |
| 32 | + |
| 33 | + |
| 34 | +# pyrogram imports |
| 35 | +from pyrogram.types import Message |
2 | 36 | from pyrogram import Client, filters |
3 | | -from RknDeveloper.untils.database import all_users, all_groups |
| 37 | +from pyrogram.errors import FloodWait, InputUserDeactivated, UserIsBlocked, PeerIdInvalid |
| 38 | + |
| 39 | +# bots imports |
| 40 | +import os, sys, time, asyncio, logging, datetime, pytz |
| 41 | +from RknDeveloper.database import rkn_botz |
4 | 42 | from configs import rkn1 |
5 | | -from pyrogram.types import Message |
6 | 43 |
|
7 | 44 |
|
8 | | -@Client.on_message(filters.command("rknusers") & filters.user(rkn1.ADMIN)) |
9 | | -async def dbtool(_, m : Message): |
10 | | - xx = all_users() |
11 | | - x = all_groups() |
12 | | - tot = int(xx + x) |
13 | | - await m.reply_text(text=f""" |
14 | | -✨ Cʜᴀᴛs Sᴛᴀᴛs ✨ |
15 | | -🙋♂️ Tᴏᴛᴀʟ Usᴇʀs : `{xx}` |
16 | | -👥 Tᴏᴛᴀʟ Gʀᴏᴜᴘs : `{x}` |
17 | | -🚧 Tᴏᴛᴀʟ Usᴇʀs & Gʀᴏᴜᴘs : `{tot}` """) |
| 45 | +@Client.on_message(filters.command(["stats", "status"]) & filters.user(rkn1.ADMIN)) |
| 46 | +async def get_stats(bot, message): |
| 47 | + total_users = await rkn_botz.total_users_count() |
| 48 | + total_chats = await rkn_botz.total_chats_count() |
| 49 | + uptime = time.strftime("%Hh%Mm%Ss", time.gmtime(time.time() - bot.uptime)) |
| 50 | + start_t = time.time() |
| 51 | + rkn = await message.reply('**ᴘʀᴏᴄᴇssɪɴɢ.....**') |
| 52 | + end_t = time.time() |
| 53 | + time_taken_s = (end_t - start_t) * 1000 |
| 54 | + await rkn.edit(text=f"**--Bᴏᴛ Sᴛᴀᴛᴜꜱ--** \n\n**⌚️ Bᴏᴛ Uᴩᴛɪᴍᴇ:** {uptime} \n**🐌 Cᴜʀʀᴇɴᴛ Pɪɴɢ:** `{time_taken_s:.3f} ᴍꜱ` \n**👭 Tᴏᴛᴀʟ Uꜱᴇʀꜱ:** `{total_users}`\n**💸 ᴛᴏᴛᴀʟ Chats:** `{total_chats}`") |
18 | 55 |
|
19 | | -@Client.on_message(filters.command("restart") & filters.user(rkn1.ADMIN)) |
| 56 | +# Restart to cancell all process |
| 57 | +@Client.on_message(filters.private & filters.command("restart") & filters.user(rkn1.ADMIN)) |
20 | 58 | async def restart_bot(b, m): |
21 | | - rknz = await m.reply_text("🔄__Rᴇꜱᴛᴀʀᴛɪɴɢ.....__") |
22 | | - await rknz.edit(f"🐾 Bᴏᴛ Rᴇsᴛᴀʀᴛᴇᴅ Cᴏᴍᴘʟᴇᴛᴇ 🐾") |
| 59 | + rkn = await b.send_message(text="**🔄 ᴘʀᴏᴄᴇssᴇs sᴛᴏᴘᴘᴇᴅ. ʙᴏᴛ ɪs ʀᴇsᴛᴀʀᴛɪɴɢ.....**", chat_id=m.chat.id) |
| 60 | + failed = 0 |
| 61 | + success = 0 |
| 62 | + deactivated = 0 |
| 63 | + blocked = 0 |
| 64 | + start_time = time.time() |
| 65 | + total_users = await rkn_botz.total_users_count() |
| 66 | + all_users = await rkn_botz.get_all_users() |
| 67 | + async for user in all_users: |
| 68 | + try: |
| 69 | + restart_msg = f"ʜᴇʏ, {(await b.get_users(user['_id'])).mention}\n\n**🔄 ᴘʀᴏᴄᴇssᴇs sᴛᴏᴘᴘᴇᴅ. ʙᴏᴛ ɪs ʀᴇsᴛᴀʀᴛɪɴɢ.....\n\n✅️ ʙᴏᴛ ɪs ʀᴇsᴛᴀʀᴛᴇᴅ. ɴᴏᴡ ʏᴏᴜ ᴄᴀɴ ᴜsᴇ ᴍᴇ.**" |
| 70 | + await b.send_message(user['_id'], restart_msg) |
| 71 | + success += 1 |
| 72 | + except InputUserDeactivated: |
| 73 | + deactivated +=1 |
| 74 | + await rkn_botz.delete_user(user['_id']) |
| 75 | + except UserIsBlocked: |
| 76 | + blocked +=1 |
| 77 | + await rkn_botz.delete_user(user['_id']) |
| 78 | + except Exception as e: |
| 79 | + failed += 1 |
| 80 | + await rkn_botz.delete_user(user['_id']) |
| 81 | + print(e) |
| 82 | + pass |
| 83 | + try: |
| 84 | + await rkn.edit(f"<u>ʀᴇsᴛᴀʀᴛ ɪɴ ᴩʀᴏɢʀᴇꜱꜱ:</u>\n\n• ᴛᴏᴛᴀʟ ᴜsᴇʀs: {total_users}\n• sᴜᴄᴄᴇssғᴜʟ: {success}\n• ʙʟᴏᴄᴋᴇᴅ ᴜsᴇʀs: {blocked}\n• ᴅᴇʟᴇᴛᴇᴅ ᴀᴄᴄᴏᴜɴᴛs: {deactivated}\n• ᴜɴsᴜᴄᴄᴇssғᴜʟ: {failed}") |
| 85 | + except FloodWait as e: |
| 86 | + await asyncio.sleep(e.value) |
| 87 | + completed_restart = datetime.timedelta(seconds=int(time.time() - start_time)) |
| 88 | + await rkn.edit(f"ᴄᴏᴍᴘʟᴇᴛᴇᴅ ʀᴇsᴛᴀʀᴛ: {completed_restart}\n\n• ᴛᴏᴛᴀʟ ᴜsᴇʀs: {total_users}\n• sᴜᴄᴄᴇssғᴜʟ: {success}\n• ʙʟᴏᴄᴋᴇᴅ ᴜsᴇʀs: {blocked}\n• ᴅᴇʟᴇᴛᴇᴅ ᴀᴄᴄᴏᴜɴᴛs: {deactivated}\n• ᴜɴsᴜᴄᴄᴇssғᴜʟ: {failed}") |
23 | 89 | os.execl(sys.executable, sys.executable, *sys.argv) |
24 | 90 |
|
| 91 | + |
| 92 | +@Client.on_message(filters.command("broadcast") & filters.user(rkn1.ADMIN) & filters.reply) |
| 93 | +async def broadcast_handler(bot: Client, m: Message): |
| 94 | + await bot.send_message(rkn1.LOG_CHANNEL, f"{m.from_user.mention} or {m.from_user.id} Iꜱ ꜱᴛᴀʀᴛᴇᴅ ᴛʜᴇ Bʀᴏᴀᴅᴄᴀꜱᴛ......") |
| 95 | + all_users = await rkn_botz.get_all_users() |
| 96 | + broadcast_msg = m.reply_to_message |
| 97 | + sts_msg = await m.reply_text("Bʀᴏᴀᴅᴄᴀꜱᴛ Sᴛᴀʀᴛᴇᴅ..!") |
| 98 | + done = 0 |
| 99 | + failed = 0 |
| 100 | + success = 0 |
| 101 | + start_time = time.time() |
| 102 | + total_users = await rkn_botz.total_users_count() |
| 103 | + async for user in all_users: |
| 104 | + sts = await send_msg(user['_id'], broadcast_msg) |
| 105 | + if sts == 200: |
| 106 | + success += 1 |
| 107 | + else: |
| 108 | + failed += 1 |
| 109 | + if sts == 400: |
| 110 | + await rkn_botz.delete_user(user['_id']) |
| 111 | + done += 1 |
| 112 | + if not done % 20: |
| 113 | + await sts_msg.edit(f"Bʀᴏᴀᴅᴄᴀꜱᴛ Iɴ Pʀᴏɢʀᴇꜱꜱ: \nTᴏᴛᴀʟ Uꜱᴇʀꜱ {total_users} \nCᴏᴍᴩʟᴇᴛᴇᴅ: {done} / {total_users}\nSᴜᴄᴄᴇꜱꜱ: {success}\nFᴀɪʟᴇᴅ: {failed}") |
| 114 | + completed_in = datetime.timedelta(seconds=int(time.time() - start_time)) |
| 115 | + await sts_msg.edit(f"Bʀᴏᴀᴅᴄᴀꜱᴛ Cᴏᴍᴩʟᴇᴛᴇᴅ: \nCᴏᴍᴩʟᴇᴛᴇᴅ Iɴ `{completed_in}`.\n\nTᴏᴛᴀʟ Uꜱᴇʀꜱ {total_users}\nCᴏᴍᴩʟᴇᴛᴇᴅ: {done} / {total_users}\nSᴜᴄᴄᴇꜱꜱ: {success}\nFᴀɪʟᴇᴅ: {failed}") |
| 116 | + |
| 117 | +async def send_msg(user_id, message): |
| 118 | + try: |
| 119 | + await message.copy(chat_id=int(user_id)) |
| 120 | + return 200 |
| 121 | + except FloodWait as e: |
| 122 | + await asyncio.sleep(e.value) |
| 123 | + return send_msg(user_id, message) |
| 124 | + except InputUserDeactivated: |
| 125 | + logger.info(f"{user_id} : Dᴇᴀᴄᴛɪᴠᴀᴛᴇᴅ") |
| 126 | + return 400 |
| 127 | + except UserIsBlocked: |
| 128 | + logger.info(f"{user_id} : Bʟᴏᴄᴋᴇᴅ Tʜᴇ Bᴏᴛ") |
| 129 | + return 400 |
| 130 | + except PeerIdInvalid: |
| 131 | + logger.info(f"{user_id} : Uꜱᴇʀ Iᴅ Iɴᴠᴀʟɪᴅ") |
| 132 | + return 400 |
| 133 | + except Exception as e: |
| 134 | + logger.error(f"{user_id} : {e}") |
| 135 | + return 500 |
| 136 | + |
| 137 | + |
| 138 | +# Rkn Developer |
| 139 | +# Don't Remove Credit 😔 |
| 140 | +# Telegram Channel @RknDeveloper & @Rkn_Botz |
| 141 | +# Developer @RknDeveloperr |
| 142 | +# Update Channel @Digital_Botz & @DigitalBotz_Support |
0 commit comments