forked from 0AIB/TG-Caption-Bot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
68 lines (62 loc) · 2.69 KB
/
main.py
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
import logging, asyncio, pyrogram, os
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
from os import environ
from pyrogram import filters, Client
from config import BOT_TOKEN, API_ID, API_HASH, CAPTION_TEXT, CAPTION_POSITION
logging.getLogger("pyrogram").setLevel(logging.WARNING)
usercaption_position = CAPTION_POSITION
caption_position = usercaption_position.lower()
CAPTION_TEXT = os.environ.get("CAPTION_TEXT", "")
CAPTION_POSITION = os.environ.get("CAPTION_POSITION", "bottom")
autocaption = Client(
"AutoCaption",
bot_token=BOT_TOKEN,
api_id=API_ID,
api_hash=API_HASH,
)
@autocaption.on_message(filters.command("start") & filters.incoming)
async def start(bot, message):
await message.reply("<I>I Am Auto Caption Bot Just Add me as a Admin in your channel with edit permission and See Magic</I>\n\n• **support** : @Hollywood_0980\n• **Source** : https://github.com/0AIB/TG-Caption-Bot")
@autocaption.on_message(filters.channel & (filters.document | filters.video | filters.audio ) & ~filters.edited, group=-1)
async def editing(bot, message):
try:
media = message.document or message.video or message.audio
caption_text = CAPTION_TEXT
except:
caption_text = ""
pass
if (message.document or message.video or message.audio):
if message.caption:
file_caption = f"**{message.caption}**"
else:
fname = media.file_name
filename = fname.replace("_", ".")
file_caption = f"`{filename}`"
try:
if caption_position == "top":
await bot.edit_message_caption(
chat_id = message.chat.id,
message_id = message.message_id,
caption = caption_text + "\n" + file_caption,
parse_mode = "markdown"
)
elif caption_position == "bottom":
await bot.edit_message_caption(
chat_id = message.chat.id,
message_id = message.message_id,
caption = file_caption + "\n\n" + caption_text,
parse_mode = "markdown"
)
elif caption_position == "nil":
await bot.edit_message_caption(
chat_id = message.chat.id,
message_id = message.message_id,
caption = caption_text,
parse_mode = "markdown"
)
except:
pass
print("Bot Started! ✨")
autocaption.run()