-
Notifications
You must be signed in to change notification settings - Fork 202
/
main.py
95 lines (82 loc) · 3.8 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
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
import pyrogram, os, asyncio
try: app_id = int(os.environ.get("app_id", None))
except Exception as app_id: print(f"⚠️ App ID Invalid {app_id}")
try: api_hash = os.environ.get("api_hash", None)
except Exception as api_id: print(f"⚠️ Api Hash Invalid {api_hash}")
try: bot_token = os.environ.get("bot_token", None)
except Exception as bot_token: print(f"⚠️ Bot Token Invalid {bot_token}")
try: custom_caption = os.environ.get("custom_caption", "`{file_name}`")
except Exception as custom_caption: print(f"⚠️ Custom Caption Invalid {custom_caption}")
AutoCaptionBot = pyrogram.Client(
name="AutoCaptionBot", api_id=app_id, api_hash=api_hash, bot_token=bot_token)
start_message = """
<b>👋Hello {}</b>
<b>I am an AutoCaption bot</b>
<b>All you have to do is add me to your channel and I will show you my power</b>
<b>@Mo_Tech_YT</b>"""
about_message = """
<b>• Name : [AutoCaption V1](t.me/{username})</b>
<b>• Developer : [Muhammed](https://github.com/PR0FESS0R-99)
<b>• Language : Python3</b>
<b>• Library : Pyrogram v{version}</b>
<b>• Updates : <a href=https://t.me/Mo_Tech_YT>Click Here</a></b>
<b>• Source Code : <a href=https://github.com/PR0FESS0R-99/AutoCaption-Bot>Click Here</a></b>"""
@AutoCaptionBot.on_message(pyrogram.filters.private & pyrogram.filters.command(["start"]))
def start_command(bot, update):
update.reply(start_message.format(update.from_user.mention), reply_markup=start_buttons(bot, update), parse_mode=pyrogram.enums.ParseMode.HTML, disable_web_page_preview=True)
@AutoCaptionBot.on_callback_query(pyrogram.filters.regex("start"))
def strat_callback(bot, update):
update.message.edit(start_message.format(update.from_user.mention), reply_markup=start_buttons(bot, update.message), parse_mode=pyrogram.enums.ParseMode.HTML, disable_web_page_preview=True)
@AutoCaptionBot.on_callback_query(pyrogram.filters.regex("about"))
def about_callback(bot, update):
bot = bot.get_me()
update.message.edit(about_message.format(version=pyrogram.__version__, username=bot.mention), reply_markup=about_buttons(bot, update.message), parse_mode=pyrogram.enums.ParseMode.HTML, disable_web_page_preview=True)
@AutoCaptionBot.on_message(pyrogram.filters.channel)
def edit_caption(bot, update: pyrogram.types.Message):
if os.environ.get("custom_caption"):
motech, _ = get_file_details(update)
try:
try: update.edit(custom_caption.format(file_name=motech.file_name))
except pyrogram.errors.FloodWait as FloodWait:
asyncio.sleep(FloodWait.value)
update.edit(custom_caption.format(file_name=motech.file_name, mote))
except pyrogram.errors.MessageNotModified: pass
else:
return
def get_file_details(update: pyrogram.types.Message):
if update.media:
for message_type in (
"photo",
"animation",
"audio",
"document",
"video",
"video_note",
"voice",
# "contact",
# "dice",
# "poll",
# "location",
# "venue",
"sticker"
):
obj = getattr(update, message_type)
if obj:
return obj, obj.file_id
def start_buttons(bot, update):
bot = bot.get_me()
buttons = [[
pyrogram.types.InlineKeyboardButton("Updates", url="t.me/Mo_Tech_YT"),
pyrogram.types.InlineKeyboardButton("About 🤠", callback_data="about")
],[
pyrogram.types.InlineKeyboardButton("➕️ Add To Your Channel ➕️", url=f"http://t.me/{bot.username}?startchannel=true")
]]
return pyrogram.types.InlineKeyboardMarkup(buttons)
def about_buttons(bot, update):
buttons = [[
pyrogram.types.InlineKeyboardButton("🏠 Back To Home 🏠", callback_data="start")
]]
return pyrogram.types.InlineKeyboardMarkup(buttons)
print("Telegram AutoCaption V1 Bot Start")
print("Bot Created By https://github.com/PR0FESS0R-99")
AutoCaptionBot.run()