Skip to content

Commit e8fb976

Browse files
authored
Update To V0.0.5 🔥
1 parent 6444d52 commit e8fb976

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed

Rkn_Bots/Caption.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# (c) @RknDeveloperr
2+
# Rkn Developer
3+
# Don't Remove Credit 😔
4+
# Telegram Channel @RknDeveloper & @Rkn_Bots
5+
# Developer @RknDeveloperr
6+
7+
from pyrogram import Client, filters, errors, types
8+
from config import Rkn_Bots
9+
import asyncio, re, time, sys
10+
from .database import total_user, getid, delete, addCap, updateCap, insert
11+
from pyrogram.errors import FloodWait
12+
13+
@Client.on_message(filters.private & filters.user(Rkn_Bots.ADMIN) & filters.command(["rknusers"]))
14+
async def all_db_users_here(client,message):
15+
x = await message.reply_text("Please Wait....")
16+
total = await total_user()
17+
await x.edit(f"Tᴏᴛᴀʟ Usᴇʀ :- `{total}`")
18+
19+
@Client.on_message(filters.private & filters.user(Rkn_Bots.ADMIN) & filters.command(["broadcast"]))
20+
async def broadcast(bot, message):
21+
if (message.reply_to_message):
22+
rkn = await message.reply_text("Geting All ids from database..\n Please wait")
23+
all_users = await getid()
24+
tot = await total_user()
25+
success = 0
26+
failed = 0
27+
deactivated = 0
28+
blocked = 0
29+
await rkn.edit(f"ʙʀᴏᴀᴅᴄᴀsᴛɪɴɢ...")
30+
async for user in all_users:
31+
try:
32+
time.sleep(1)
33+
await message.reply_to_message.copy(user['_id'])
34+
success += 1
35+
except errors.InputUserDeactivated:
36+
deactivated +=1
37+
await delete({"_id": user['_id']})
38+
except errors.UserIsBlocked:
39+
blocked +=1
40+
await delete({"_id": user['_id']})
41+
except Exception as e:
42+
failed += 1
43+
await delete({"_id": user['_id']})
44+
pass
45+
try:
46+
await rkn.edit(f"<u>ʙʀᴏᴀᴅᴄᴀsᴛ ᴘʀᴏᴄᴇssɪɴɢ</u>\n\n• ᴛᴏᴛᴀʟ ᴜsᴇʀs: {tot}\n• sᴜᴄᴄᴇssғᴜʟ: {success}\n• ʙʟᴏᴄᴋᴇᴅ ᴜsᴇʀs: {blocked}\n• ᴅᴇʟᴇᴛᴇᴅ ᴀᴄᴄᴏᴜɴᴛs: {deactivated}\n• ᴜɴsᴜᴄᴄᴇssғᴜʟ: {failed}")
47+
except FloodWait as e:
48+
await asyncio.sleep(t.x)
49+
await rkn.edit(f"<u>ʙʀᴏᴀᴅᴄᴀsᴛ ᴄᴏᴍᴘʟᴇᴛᴇᴅ</u>\n\n• ᴛᴏᴛᴀʟ ᴜsᴇʀs: {tot}\n• sᴜᴄᴄᴇssғᴜʟ: {success}\n• ʙʟᴏᴄᴋᴇᴅ ᴜsᴇʀs: {blocked}\n• ᴅᴇʟᴇᴛᴇᴅ ᴀᴄᴄᴏᴜɴᴛs: {deactivated}\n• ᴜɴsᴜᴄᴄᴇssғᴜʟ: {failed}")
50+
51+
#Restart to cancell all process
52+
@Client.on_message(filters.private & filters.user(Rkn_Bots.ADMIN) & filters.command("restart"))
53+
async def restart_bot(b, m):
54+
msg = await b.send_message(text="**🔄 𝙿𝚁𝙾𝙲𝙴𝚂𝚂𝙴𝚂 𝚂𝚃𝙾𝙿𝙴𝙳. 𝙱𝙾𝚃 𝙸𝚂 𝚁𝙴𝚂𝚃𝙰𝚁𝚃𝙸𝙽𝙶...**", chat_id=m.chat.id)
55+
await asyncio.sleep(3)
56+
await msg.edit("**✅️ 𝙱𝙾𝚃 𝙸𝚂 𝚁𝙴𝚂𝚃𝙰𝚁𝚃𝙴𝙳. 𝙽𝙾𝚆 𝚈𝙾𝚄 𝙲𝙰𝙽 𝚄𝚂𝙴 𝙼𝙴**")
57+
os.execl(sys.executable, sys.executable, *sys.argv)
58+
59+
@Client.on_message(filters.command("start") & filters.private)
60+
async def start_cmd(bot, message):
61+
user_id = int(message.from_user.id)
62+
await insert(user_id)
63+
await message.reply(
64+
f"<b>Hey, {message.from_user.mention}\n\nI'm an auto-caption bot. I automatically edit captions for videos, audio files, and documents posted on channels.\n\nuse <code>/set_caption</code> to set caption\nUse<code>/delcaption</code> To delete caption and set caption to default.\n\nNote:All commands works on channels only</b>",
65+
reply_markup=types.InlineKeyboardMarkup([[
66+
types.InlineKeyboardButton('Uᴩᴅᴀᴛᴇꜱ', url='https://t.me/RknDeveloper'),
67+
types.InlineKeyboardButton('Sᴜᴩᴩᴏʀᴛ', url='https://t.me/Rkn_Bots_Support')
68+
],[
69+
types.InlineKeyboardButton('🔥 Source Code 🔥', url='https://github.com/RknDeveloper/Rkn-AutoCaptionBot')
70+
]]))
71+
72+
73+
74+
@Client.on_message(filters.command("set_caption") & filters.channel)
75+
async def setCap(bot, message):
76+
if len(message.command) < 2:
77+
return await message.reply(
78+
"Usage: /set_caption <code>your caption (use {file_name} to show file name</code>)"
79+
)
80+
chnl_id = message.chat.id
81+
caption = (
82+
message.text.split(" ", 1)[1] if len(message.text.split(" ", 1)) > 1 else None
83+
)
84+
chkData = await chnl_ids.find_one({"chnl_id": chnl_id})
85+
if chkData:
86+
await updateCap(chnl_id, caption)
87+
return await message.reply(f"Your New Caption: {caption}")
88+
else:
89+
await addCap(chnl_id, caption)
90+
return await message.reply(f"Your New Caption: {caption}")
91+
92+
93+
@Client.on_message(filters.command(["delcaption", "del_caption", "delete_caption"]) & filters.channel)
94+
async def delCap(_, msg):
95+
chnl_id = msg.chat.id
96+
try:
97+
await chnl_ids.delete_one({"chnl_id": chnl_id})
98+
return await msg.reply("<b>Success..From now i will use my default caption</b>")
99+
except Exception as e:
100+
e_val = await msg.replay(f"ERR I GOT: {e}")
101+
await asyncio.sleep(5)
102+
await e_val.delete()
103+
return
104+
105+
106+
@Client.on_message(filters.channel)
107+
async def auto_edit_caption(bot, message):
108+
chnl_id = message.chat.id
109+
if message.media:
110+
for file_type in ("video", "audio", "document", "voice"):
111+
obj = getattr(message, file_type, None)
112+
if obj and hasattr(obj, "file_name"):
113+
file_name = obj.file_name
114+
file_name = (
115+
re.sub(r"@\w+\s*", "", file_name)
116+
.replace("_", " ")
117+
.replace(".", " ")
118+
)
119+
cap_dets = await chnl_ids.find_one({"chnl_id": chnl_id})
120+
try:
121+
if cap_dets:
122+
cap = cap_dets["caption"]
123+
replaced_caption = cap.format(file_name=file_name)
124+
await message.edit(replaced_caption)
125+
else:
126+
replaced_caption = Rkn_Bots.DEF_CAP.format(file_name=file_name)
127+
await message.edit(replaced_caption)
128+
except FloodWait as e:
129+
await asyncio.sleep(e.x)
130+
continue
131+
return
132+
133+
# Rkn Developer
134+
# Don't Remove Credit 😔
135+
# Telegram Channel @RknDeveloper & @Rkn_Bots
136+
# Developer @RknDeveloperr

0 commit comments

Comments
 (0)