Skip to content

Commit f5b887d

Browse files
authored
Updated v2.0.0 version lastest @RknDeveloper
1 parent 70cf9d5 commit f5b887d

6 files changed

Lines changed: 482 additions & 18 deletions

File tree

RknDeveloper/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Telegram MTProto API Client Library for Pyrogram
2-
# Copyright (C) 2017-present RknDeveloper <https://github.com/RknDeveloper>
2+
# Copyright (C) 2017-present DigitalBotz <https://github.com/DigitalBotz>
33
# I am a telegram bot, I created it using pyrogram library. https://github.com/pyrogram
44
"""
55
Apache License 2.0
@@ -26,7 +26,7 @@
2626
"""
2727

2828
__name__ = "Auto-Request-Approve-Bot"
29-
__version__ = "1.0.0"
29+
__version__ = "2.0.0"
3030
__license__ = " Apache License, Version 2.0"
3131
__copyright__ = "Copyright (C) 2022-present Rkn Developer <https://github.com/RknDeveloper>"
3232
__programer__ = "<a href=https://github.com/RknDeveloper/Rkn_Auto-Request-Approve-bot>RknDeveloper</a>"
@@ -38,3 +38,5 @@
3838

3939
# main copyright herders (©️)
4040
# I have been working on this repo since 2022
41+
42+

RknDeveloper/admin.py

Lines changed: 134 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,142 @@
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
236
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
442
from configs import rkn1
5-
from pyrogram.types import Message
643

744

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}`")
1855

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))
2058
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}")
2389
os.execl(sys.executable, sys.executable, *sys.argv)
2490

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

RknDeveloper/database.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# (c) @RknDeveloperr
2+
# Rkn Developer
3+
# Don't Remove Credit 😔
4+
# Telegram Channel @RknDeveloper & @Rkn_Bots
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+
# database imports
34+
import motor.motor_asyncio, datetime, pytz
35+
36+
# bots imports
37+
from configs import rkn1
38+
39+
class Database:
40+
def __init__(self, uri, database_name):
41+
self._client = motor.motor_asyncio.AsyncIOMotorClient(uri)
42+
self.db = self._client[database_name]
43+
self.col = self.db.user
44+
self.chat = self.db.chat
45+
46+
def new_user(self, id):
47+
return dict(_id=int(id))
48+
49+
50+
async def add_user(self, b, m):
51+
u = m.from_user
52+
if not await self.is_user_exist(u.id):
53+
user = self.new_user(u.id)
54+
await self.col.insert_one(user)
55+
await self.send_user_log(b, u)
56+
57+
async def is_user_exist(self, id):
58+
user = await self.col.find_one({'_id': int(id)})
59+
return bool(user)
60+
61+
async def total_users_count(self):
62+
count = await self.col.count_documents({})
63+
return count
64+
65+
async def get_all_users(self):
66+
all_users = self.col.find({})
67+
return all_users
68+
69+
async def delete_user(self, user_id):
70+
await self.col.delete_many({'_id': int(user_id)})
71+
72+
async def send_user_log(self, b, u):
73+
if rkn1.LOG_CHANNEL is not None:
74+
await b.send_message(
75+
rkn1.LOG_CHANNEL,
76+
f"**--Nᴇᴡ Uꜱᴇʀ Sᴛᴀʀᴛᴇᴅ Tʜᴇ Bᴏᴛ--**\n\nUꜱᴇʀ: {u.mention}\nIᴅ: `{u.id}`\nUɴ: @{u.username}\n\nBy: {b.mention}"
77+
)
78+
79+
async def add_chat(self, b, m):
80+
if not await self.is_user_exist(m.chat.id):
81+
user = self.new_user(m.chat.id)
82+
await self.chat.insert_one(user)
83+
await self.send_chat_log(b, m)
84+
85+
async def is_chat_exist(self, id):
86+
user = await self.chat.find_one({'_id': int(id)})
87+
return bool(user)
88+
89+
async def total_chats_count(self):
90+
count = await self.chat.count_documents({})
91+
return count
92+
93+
async def get_all_chats(self):
94+
all_users = self.chat.find({})
95+
return all_users
96+
97+
async def delete_chat(self, user_id):
98+
await self.chat.delete_many({'_id': int(user_id)})
99+
100+
async def send_chat_log(self, b, m):
101+
if rkn1.LOG_CHANNEL is not None:
102+
await b.send_message(
103+
rkn1.LOG_CHANNEL,
104+
f"**--Nᴇᴡ Uꜱᴇʀ Sᴛᴀʀᴛᴇᴅ Tʜᴇ Bᴏᴛ--**\n\nUꜱᴇʀ: {m.chat.title}\nIᴅ: `{m.chat.id}`\nUɴ: @{m.chat.username}\n\nBy: {m.from_user.mention} & {b.mention}"
105+
)
106+
107+
rkn_botz = Database(rkn1.DB_URL, rkn1.DB_NAME)
108+
109+
# Rkn Developer
110+
# Don't Remove Credit 😔
111+
# Telegram Channel @RknDeveloper & @Rkn_Bots
112+
# Developer @RknDeveloperr
113+
# Update Channel @Digital_Botz & @DigitalBotz_Support

RknDeveloper/fs.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
# pyrogram imports
34+
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
35+
from pyrogram.errors import UserNotParticipant
36+
37+
async def force_sub(bot, message, sub_id):
38+
chat = await bot.get_chat(int(sub_id))
39+
try:
40+
await bot.get_chat_member(sub_id, message.from_user.id)
41+
except UserNotParticipant:
42+
return await message.reply_text(f"👋 Hello {message.from_user.mention},\n\nPlease join my 'Updates Channel'. 😇",
43+
reply_markup=InlineKeyboardMarkup([[
44+
InlineKeyboardButton(f'Join {chat.title}', url=chat.invite_link)
45+
]]))
46+
except Exception as e:
47+
pass
48+
49+
50+
51+
# Rkn Developer
52+
# Don't Remove Credit 😔
53+
# Telegram Channel @RknDeveloper & @Rkn_Botz
54+
# Developer @RknDeveloperr
55+
# Update Channel @Digital_Botz & @DigitalBotz_Support

0 commit comments

Comments
 (0)