Repository navigation
Expand file tree
/
Copy pathconfig.py
More file actions
253 lines (224 loc) · 13.6 KB
/
Copy pathconfig.py
File metadata and controls
253 lines (224 loc) · 13.6 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
import re, os, time
from helper.smallcaps import sc
id_pattern = re.compile(r'^.\d+$')
class Config(object):
# bot client config
API_ID = os.environ.get("API_ID", "")
API_HASH = os.environ.get("API_HASH", "")
BOT_TOKEN = os.environ.get("BOT_TOKEN", "")
BOT = None
# premium account string session required!
STRING_SESSION = os.environ.get("STRING_SESSION", "")
# database config
DB_NAME = os.environ.get("DB_NAME","Adv-RenameBot")
DB_URL = os.environ.get("DB_URL","")
# other configs
IMAGE_URL = [
"https://i.pinimg.com/originals/74/b1/e8/74b1e8dc9594784e67db724d46e5faf7.jpg",
"https://i.pinimg.com/originals/6a/3d/d4/6a3dd41dfb4d1b0406e5be3fdb63a31a.jpg",
"https://i.pinimg.com/originals/4d/4b/99/4d4b9949849ac62994be0ad870b26733.jpg",
"https://i.pinimg.com/originals/9e/3b/53/9e3b53bbd02b185c38b44a8ff31f5209.jpg",
"https://i.pinimg.com/originals/eb/d4/9d/ebd49d466cfa766f1a6fb10b82fa1914.jpg"
]
ADMIN = [int(admin) if id_pattern.search(admin) else admin for admin in os.environ.get('ADMIN', '0').split()]
LOG_CHANNEL = int(os.environ.get("LOG_CHANNEL", "0"))
# free upload limit
FREE_UPLOAD_LIMIT = 6442450944 # calculation 6*1024*1024*1024=results
# premium mode feature
UPLOAD_LIMIT_MODE = True
PREMIUM_MODE = True
# performance tuning (safe to raise on a high-bandwidth VPS, lower it
# again if you start seeing FloodWaits). Values below match what
# well-optimized Pyrogram leech bots (mirror-leech-telegram-bot /
# WZML-X family) ship as defaults.
# MAX_CONCURRENT_TRANSMISSIONS -> parallel chunks used INSIDE a single
# download/upload (Pyrogram/pyrofork default is 1, which is very slow
# for large files). Applies to both the bot-token client and the
# premium string-session client.
MAX_CONCURRENT_TRANSMISSIONS = max(1, min(int(os.environ.get("MAX_CONCURRENT_TRANSMISSIONS", "16")), 256))
# MAX_PARALLEL_TRANSFERS -> how many files can be downloading/uploading
# across the whole bot AT THE SAME TIME. Keeps multiple users' files
# running together without overloading the VPS or triggering FloodWait.
MAX_PARALLEL_TRANSFERS = max(1, min(int(os.environ.get("MAX_PARALLEL_TRANSFERS", "8")), 16))
# Media jobs write complete files to disk. Keep the existing transfer
# default for compatibility, but make it independently measurable and
# tunable from the deployment environment.
MAX_ACTIVE_TRANSFERS = max(1, min(int(os.environ.get(
"MAX_ACTIVE_TRANSFERS", str(MAX_PARALLEL_TRANSFERS)
)), 16))
# FFmpeg remuxing competes directly with download/upload disk I/O. One is
# deliberately conservative until a production benchmark establishes a
# safe value for a particular host.
MAX_FFMPEG_JOBS = max(1, min(int(os.environ.get("MAX_FFMPEG_JOBS", "1")), 8))
FFMPEG_TIMEOUT_SECONDS = max(60, int(os.environ.get("FFMPEG_TIMEOUT_SECONDS", "7200")))
# Admission reserve is in addition to the estimated live files. It gives
# the OS and concurrent cleanup room without hard-coding host capacity.
DISK_SAFETY_HEADROOM_MB = max(0, int(os.environ.get("DISK_SAFETY_HEADROOM_MB", "1024")))
THUMBNAIL_RESERVE_MB = max(1, int(os.environ.get("THUMBNAIL_RESERVE_MB", "32")))
WORKSPACE_ROOT = os.environ.get("WORKSPACE_ROOT", "workspaces")
# MAX_MESSAGE_CACHE_SIZE -> Pyrogram's in-memory message/topic cache.
# Bigger cache avoids extra get_messages round-trips under load.
MAX_MESSAGE_CACHE_SIZE = max(1000, min(int(os.environ.get("MAX_MESSAGE_CACHE_SIZE", "20000")), 100000))
# BOT_SLEEP_THRESHOLD -> 0 means the bot-token client never auto-sleeps
# on a FloodWait internally; it raises immediately so our own retry
# logic (see plugins/file_rename.py) handles it instead of Pyrogram
# silently blocking the connection.
BOT_SLEEP_THRESHOLD = int(os.environ.get("BOT_SLEEP_THRESHOLD", "0"))
# PREMIUM_SLEEP_THRESHOLD -> the premium/string-session client is only
# used for background transfers, so a longer auto-sleep is fine here.
PREMIUM_SLEEP_THRESHOLD = int(os.environ.get("PREMIUM_SLEEP_THRESHOLD", "60"))
# Large-file transfer tuning. 64 concurrent MTProto transmission slots is
# intentionally aggressive without being the pathological 1000-slot
# setting; raise to 96/128 via env on a strong VPS if benchmarking proves
# the extra concurrency helps.
TRANSFER_RETRIES = max(1, min(int(os.environ.get("TRANSFER_RETRIES", "3")), 6))
PROGRESS_UPDATE_INTERVAL = max(1.0, float(os.environ.get("PROGRESS_UPDATE_INTERVAL", "2.0")))
FAST_MTPROTO_SESSIONS = max(4, min(int(os.environ.get("FAST_MTPROTO_SESSIONS", "6")), 16))
# ---- Watchdog / auto-recovery -------------------------------------
# Silent self-restart (no messages sent) when memory is nearly full AND no
# task is running, or when the bot is frozen / disconnected.
WATCHDOG_ENABLED = os.environ.get("WATCHDOG_ENABLED", "1").lower() not in ("0", "false", "no", "off")
# Restart when used memory (container limit if any, else system RAM) >= this %.
MEMORY_RESTART_PERCENT = max(50, min(int(os.environ.get("MEMORY_RESTART_PERCENT", "85")), 99))
# Optional absolute cap for the bot process itself (MB). 0 = disabled.
MEMORY_RESTART_MB = max(0, int(os.environ.get("MEMORY_RESTART_MB", "0")))
# Bot must have been idle (no task at all) for this long before a memory restart.
IDLE_RESTART_SECONDS = max(10, int(os.environ.get("IDLE_RESTART_SECONDS", "60")))
# Never restart for memory earlier than this after (re)start - avoids restart loops.
MIN_UPTIME_BEFORE_RESTART = max(60, int(os.environ.get("MIN_UPTIME_BEFORE_RESTART", "600")))
WATCHDOG_INTERVAL = max(5, int(os.environ.get("WATCHDOG_INTERVAL", "30")))
# Telegram connection health check (ping) every N seconds; restart after N misses.
HEALTH_PING_INTERVAL = max(15, int(os.environ.get("HEALTH_PING_INTERVAL", "60")))
HEALTH_FAIL_LIMIT = max(2, int(os.environ.get("HEALTH_FAIL_LIMIT", "3")))
# If the asyncio event loop makes no progress for this long, it is frozen -> restart.
LOOP_FREEZE_SECONDS = max(30, int(os.environ.get("LOOP_FREEZE_SECONDS", "120")))
# Keep-alive: the bot pings its own public URL so free hosts (Render/Koyeb/...)
# do not put it to sleep. Auto-detected from RENDER_EXTERNAL_URL / KOYEB_PUBLIC_DOMAIN.
SELF_PING_URL = (os.environ.get("SELF_PING_URL")
or os.environ.get("RENDER_EXTERNAL_URL")
or (("https://" + os.environ["KOYEB_PUBLIC_DOMAIN"]) if os.environ.get("KOYEB_PUBLIC_DOMAIN") else ""))
SELF_PING_INTERVAL = max(60, int(os.environ.get("SELF_PING_INTERVAL", "240")))
#force subs
try:
FORCE_SUB = int(os.environ.get("FORCE_SUB", ""))
except:
FORCE_SUB = os.environ.get("FORCE_SUB", "Unrated_Coder")
# wes response configuration
PORT = int(os.environ.get("PORT", "8080"))
BOT_UPTIME = time.time()
class Txt(object):
# every text below is plain english; it is converted to lowercase small caps
# automatically at the bottom of this file (html tags / {placeholders} /
# <code> blocks / links are left untouched).
START_TXT = """<b>✨ » hey, {}! welcome 👋</b>
<blockquote><b>🚀 i am an advanced & high-speed telegram rename bot!</b>
send me any file, video or audio and i will rename it in seconds.</blockquote>
<blockquote><b><u>⚡ key features</u></b>
• <b>rename files & videos</b> with lightning speed
• <b>custom thumbnail</b> & <b>custom caption</b>
• <b>prefix & suffix</b> for every filename
• <b>custom metadata</b> editor for media files
• convert <b>video to file</b> & <b>file to video</b> instantly
• <b>2gb+</b> large file support</blockquote>
<b>👇 tap help to learn how to use me, or about to know more.</b>"""
ABOUT_TXT = """<b>✦ <u>about this bot</u></b>
<blockquote><b>🤖 bot name :</b> {botname}
<b>🖥️ developer :</b> <a href="https://t.me/AniReal_Support"><b>Eren Yeager</b></a>
<b>👨💻 maintainer :</b> <a href="https://t.me/Unrated_Coder"><b>Unrated Coder™</b></a>
<b>📊 version :</b> {version}</blockquote>
<b>need help?</b> contact <a href="https://t.me/Og_Luffytaro"><b>Luffytaro シ</b></a>"""
HELP_TXT = """<b>✦ <u>user guide & help menu</u></b>
<blockquote><b>1. how to rename a file:</b>
• send any document, video, or audio file.
• enter the desired new file name.
• choose output format (<b>document</b>, <b>video</b>, or <b>audio</b>).</blockquote>
<b>👇 pick a topic below for more details.</b>"""
PREMIUM_FREE = """<b>🎉 all premium features are active for free!</b>
<blockquote>no purchase needed — enjoy unlimited everything! 🥳</blockquote>"""
UPGRADE_PREMIUM = """💎 <b><u>premium subscription plans</u></b>
<blockquote>★ <b>bronze plan :</b> 3 days — ₹39
★ <b>silver plan :</b> 7 days — ₹59
★ <b>gold plan :</b> 15 days — ₹99
★ <b>platinum plan :</b> 1 month — ₹179
★ <b>diamond plan :</b> 2 months — ₹339</blockquote>
<blockquote><b><u>⚡ premium benefits :</u></b>
• <b>unlimited</b> daily uploads.
• <b>high-speed</b> priority processing.
• <b>4gb+</b> large file support.</blockquote>
<i>🏷️ special discount: ₹9 off on all plans!</i>
💳 <b>contact admin :</b> <a href="https://t.me/Og_Luffytaro"><b>Luffytaro シ</b></a>"""
UPGRADE_PLAN = """💎 <b><u>pro upload limit plans</u></b>
<blockquote>🔹 <b>plan : pro</b>
• <b>duration :</b> 1 month | <b>limit :</b> 100 gb
• <b>price :</b> ₹179
🔹 <b>plan : ultra pro</b>
• <b>duration :</b> 1 month | <b>limit :</b> 1000 gb
• <b>price :</b> ₹199</blockquote>
<i>🏷️ discount on all plans: ₹9 off!</i>
💳 <b>buy now :</b> <a href="https://t.me/sitaratoons_support"><b>A.C</b></a>"""
THUMBNAIL = """🖼️ <b><u>custom thumbnail settings</u></b>
<blockquote>• <b>set thumbnail :</b> send any photo directly to save it.
• <b>view thumbnail :</b> /view_thumb (to view current)
• <b>delete thumbnail :</b> /del_thumb (to remove)</blockquote>"""
CAPTION = """📝 <b><u>custom caption settings</u></b>
<blockquote>• <b>set caption :</b> <code>/set_caption [caption]</code>
• <b>view caption :</b> /see_caption
• <b>delete caption :</b> /del_caption</blockquote>
<blockquote><b><u>🏷️ dynamic tags :</u></b>
• <code>{filename}</code> — file name
• <code>{filesize}</code> — file size
• <code>{duration}</code> — media duration</blockquote>
<b><u>📌 example :</u></b>
<code>/set_caption 🎬 File: {filename}
💾 Size: {filesize}
⏰ Duration: {duration}</code>"""
BOT_STATUS = """⚡ <b><u>current bot statistics</u></b>
<blockquote>⏱️ <b>uptime :</b> <code>{}</code>
👥 <b>total users :</b> <code>{}</code>
💎 <b>premium users :</b> <code>{}</code>
⬆️ <b>uploaded :</b> <code>{}</code>
⬇️ <b>downloaded :</b> <code>{}</code></blockquote>"""
CUSTOM_FILE_NAME = """✒️ <b><u>custom prefix & suffix settings</u></b>
<blockquote><b><u>🔹 prefix (before filename):</u></b>
• <code>/set_prefix [Prefix]</code> — set prefix
• <code>/see_prefix</code> — view prefix
• <code>/del_prefix</code> — delete prefix</blockquote>
<blockquote><b><u>🔸 suffix (after filename):</u></b>
• <code>/set_suffix [Suffix]</code> — set suffix
• <code>/see_suffix</code> — view suffix
• <code>/del_suffix</code> — delete suffix</blockquote>
💡 <b>example :</b> <code>/set_prefix [HEVC]</code> or <code>/set_suffix @Unrated_Coder</code>"""
DEV_TXT = """✨ <b><u>special thanks & credits</u></b>
<blockquote>» <b>source code :</b> <a href="https://github.com/Unrated-Coder/adv-RenameBot.git"><b>advanced rename bot</b></a></blockquote>
<blockquote><b>❣️ <u>developers & supporters :</u></b>
• <a href="https://t.me/AniReal_Support"><b>Eren Yeager</b></a>
• <a href="https://t.me/Og_Luffytaro"><b>Luffytaro シ</b></a>
• <a href="https://t.me/DoraShin_hlo"><b>➳≛⃝ Gojo ××</b></a>
• <a href="https://t.me/sitaratoons_support"><b>A.C</b></a>
• <a href="https://t.me/JustThreshold"><b>Sudo User</b></a></blockquote>
<b>» maintainer</b> — <a href="https://t.me/Unrated_Coder"><b>Unrated Coder™</b></a>"""
METADATA = """🏷️ <b><u>custom metadata setup</u></b>
<blockquote>⚙️ <b><u>metadata menu guide:</u></b>
• send <code>/metadata</code> to open the interactive settings.
• use <b>inline buttons</b> to configure your tags easily.</blockquote>
<blockquote><b><u>✨ available options :</u></b>
• <b>single metadata tag :</b> set one tag, and it auto-applies to all streams (title, video, audio & subtitle).
• <b>official site tag :</b> add your website link (optional).</blockquote>
💡 <b>note :</b> official site tag is completely optional. metadata will work smoothly even without it!"""
SEND_METADATA = """🏷️ <b><u>set custom metadata</u></b>
<blockquote>reply to this message with your <b>metadata tag / text</b>.</blockquote>
<blockquote><b><u>⚡ how it works:</u></b>
• your single tag will be automatically applied to <b>all streams</b> (title, video, audio & subtitle).</blockquote>
💡 <b>example :</b> <code>@Unrated_Coder</code> or <code>Encoded By Luffytaro</code>"""
PROGRESS_BAR = """<b>
┌━━━━━━━━━━━━━━━━━━━━┐
├ 🚀 <b>Status:</b> {5}
├ 📦 <b>Size:</b> {1} / {2}
├ 📊 <b>Progress:</b> {0}%
├ ⚡ <b>Speed:</b> {3}/ꜱ
├ ⏰ <b>ETA:</b> {4}
└━━━━━━━━━━━━━━━━━━━━┘</b>"""
# convert every Txt.* string to lowercase small caps once, at import time
for _name, _val in list(vars(Txt).items()):
if isinstance(_val, str) and not _name.startswith("__"):
setattr(Txt, _name, sc(_val))