Skip to content

Commit 1a54d7d

Browse files
committed
v 0.1
0 parents  commit 1a54d7d

15 files changed

+1612
-0
lines changed

Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM python:3.9.2-slim-buster
2+
RUN mkdir /bot && chmod 777 /bot
3+
WORKDIR /bot
4+
ENV DEBIAN_FRONTEND=noninteractive
5+
RUN apt -qq update && apt -qq install -y git wget pv jq wget python3-dev ffmpeg mediainfo && pip3 install python-decouple telethon requests
6+
COPY . .
7+
CMD ["bash","run.sh"]

License

+674
Large diffs are not rendered by default.

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bot: python3 start.py

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div dir="ltr" style="text-align: left;" trbidi="on">
2+
<h3 style="background-color: white; box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 1.25em; line-height: 1.25; margin-bottom: 16px; margin-top: 0px !important;">
3+
𝕍𝕚𝕕𝕖𝕠 ℂ𝕆𝕄ℙℝ𝔼𝕊𝕊𝕆ℝ 𝔹𝕆𝕋</h3>
4+
<div style="background-color: white; box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 16px; margin-bottom: 16px;">
5+
ᴍᴜʟᴛɪғᴜɴᴄᴛɪᴏɴ ǫᴜᴀʟɪᴛʏ ᴄᴏᴍᴘʀᴇssᴏʀ</div>
6+
<div style="background-color: white; box-sizing: border-box; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 16px; margin-bottom: 16px;">
7+
<a href="https://dashboard.heroku.com/new?button-url=https%3A%2F%2Fgithub.com%2F1Danish-00%2FCompressorBotp&amp;template=https%3A%2F%2Fgithub.com%2F1Danish-00%2FCompressorBot" rel="nofollow" style="background-color: initial; box-sizing: border-box; color: #0366d6; text-decoration-line: none;"><img alt="Deploy" data-canonical-src="https://www.herokucdn.com/deploy/button.svg" src="https://camo.githubusercontent.com/83b0e95b38892b49184e07ad572c94c8038323fb/68747470733a2f2f7777772e6865726f6b7563646e2e636f6d2f6465706c6f792f627574746f6e2e737667" style="border-style: none; box-sizing: initial; max-width: 100%;" /></a></div>

app.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "CompressorBot",
3+
"description": "A Normal Telegram Bot Which can Compress/encode/ Generate Samples of videos.",
4+
"logo": " #https://telegra.ph/file/75ee20ec8d8c8bba84f02.jpg",
5+
"keywords": ["Telegram","python", "Video","Compressor","Encoder"],
6+
"repository": "https://github.com/1Danish-00/CompressorBot",
7+
"success_url": "https://t.me/danish_00",
8+
"stack": "container",
9+
"env": {
10+
"APP_ID": {
11+
"description": "You api id, from my.telegram.org or @apiScrapperRoBot.",
12+
"value": ""
13+
},
14+
"API_HASH": {
15+
"description": "You api hash, from my.telegram.org or @apiScrapperRoBot.",
16+
"value": ""
17+
},
18+
"BOT_TOKEN": {
19+
"description": "Make a bot from @BotFather, and enter it's api token here.",
20+
"value": ""
21+
},
22+
"OWNER_ID": {
23+
"description": "Get ur Id Of Telegram nd Paste Here.",
24+
"value": ""
25+
},
26+
"LOG_CHANNEL": {
27+
"description": "Create a private group. Add @missrose_bot and your bot. Do /id. Paste that here",
28+
"value": ""
29+
}
30+
}
31+
}

helper/__init__.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This file is part of the Compressor distribution.
2+
# Copyright (c) 2021 Danish_00
3+
#
4+
# This program is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, version 3.
7+
#
8+
# This program is distributed in the hope that it will be useful, but
9+
# WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
# General Public License for more details.
12+
#
13+
# License can be found in < https://github.com/1Danish-00/CompressorBot/blob/main/License> .
14+
15+
16+
import os
17+
import re
18+
import io
19+
import sys
20+
import math
21+
import glob
22+
import time
23+
import json
24+
import shutil
25+
import asyncio
26+
import inspect
27+
import requests
28+
import traceback
29+
import subprocess
30+
import telethon.utils
31+
from pathlib import Path
32+
from decouple import config
33+
from datetime import datetime as dt
34+
35+
from telethon.sessions import StringSession
36+
from telethon.utils import get_display_name
37+
from telethon.tl.functions.users import GetFullUserRequest
38+
from logging import basicConfig, getLogger, INFO, DEBUG, warning
39+
from telethon.tl.functions.messages import ExportChatInviteRequest as cl
40+
from telethon import TelegramClient, events, Button, errors, functions, types

helper/_get.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .devtools import *

helper/config.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This file is part of the Compressor distribution.
2+
# Copyright (c) 2021 Danish_00
3+
#
4+
# This program is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, version 3.
7+
#
8+
# This program is distributed in the hope that it will be useful, but
9+
# WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
# General Public License for more details.
12+
#
13+
# License can be found in < https://github.com/1Danish-00/CompressorBot/blob/main/License> .
14+
15+
from . import *
16+
17+
try:
18+
APP_ID = config("APP_ID", cast=int)
19+
API_HASH = config("API_HASH")
20+
BOT_TOKEN = config("BOT_TOKEN")
21+
OWNER = config("OWNER_ID", default=1322549723, cast=int)
22+
LOG = config("LOG_CHANNEL", cast=int)
23+
except Exception as e:
24+
LOGS.info("Environment vars Missing")
25+
LOGS.info("something went wrong")
26+
LOGS.info(str(e))
27+
exit(1)

helper/devtools.py

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# This file is part of the Compressor distribution.
2+
# Copyright (c) 2021 Danish_00
3+
#
4+
# This program is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, version 3.
7+
#
8+
# This program is distributed in the hope that it will be useful, but
9+
# WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
# General Public License for more details.
12+
#
13+
# License can be found in < https://github.com/1Danish-00/CompressorBot/blob/main/License> .
14+
15+
from .stuff import *
16+
17+
18+
async def eval(event):
19+
if event.sender_id != OWNER:
20+
return
21+
await event.reply("Processing ...")
22+
cmd = event.text.split(" ", maxsplit=1)[1]
23+
old_stderr = sys.stderr
24+
old_stdout = sys.stdout
25+
redirected_output = sys.stdout = io.StringIO()
26+
redirected_error = sys.stderr = io.StringIO()
27+
stdout, stderr, exc = None, None, None
28+
try:
29+
await aexec(cmd, event)
30+
except Exception:
31+
exc = traceback.format_exc()
32+
stdout = redirected_output.getvalue()
33+
stderr = redirected_error.getvalue()
34+
sys.stdout = old_stdout
35+
sys.stderr = old_stderr
36+
evaluation = ""
37+
if exc:
38+
evaluation = exc
39+
elif stderr:
40+
evaluation = stderr
41+
elif stdout:
42+
evaluation = stdout
43+
else:
44+
evaluation = "Success"
45+
final_output = "**EVAL**: `{}` \n\n **OUTPUT**: \n`{}` \n".format(cmd, evaluation)
46+
if len(final_output) > 4095:
47+
with io.BytesIO(str.encode(final_output)) as out_file:
48+
out_file.name = "eval.text"
49+
await event.client.send_file(
50+
event.chat_id,
51+
out_file,
52+
force_document=True,
53+
allow_cache=False,
54+
caption=cmd,
55+
)
56+
await event.delete()
57+
else:
58+
await event.reply(final_output)
59+
60+
61+
async def aexec(code, event):
62+
exec(f"async def __aexec(event): " + "".join(f"\n {l}" for l in code.split("\n")))
63+
return await locals()["__aexec"](event)
64+
65+
66+
async def bash(event):
67+
if event.sender_id != OWNER:
68+
return
69+
cmd = event.text.split(" ", maxsplit=1)[1]
70+
process = await asyncio.create_subprocess_shell(
71+
cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
72+
)
73+
stdout, stderr = await process.communicate()
74+
e = stderr.decode()
75+
if not e:
76+
e = "No Error"
77+
o = stdout.decode()
78+
if not o:
79+
o = "**Tip**: \n`If you want to see the results of your code, I suggest printing them to stdout.`"
80+
else:
81+
_o = o.split("\n")
82+
o = "`\n".join(_o)
83+
OUTPUT = f"**QUERY:**\n__Command:__\n`{cmd}` \n__PID:__\n`{process.pid}`\n\n**stderr:** \n`{e}`\n**Output:**\n{o}"
84+
if len(OUTPUT) > 4095:
85+
with io.BytesIO(str.encode(OUTPUT)) as out_file:
86+
out_file.name = "exec.text"
87+
await event.client.send_file(
88+
event.chat_id,
89+
out_file,
90+
force_document=True,
91+
allow_cache=False,
92+
caption=cmd,
93+
)
94+
await event.delete()
95+
await event.reply(OUTPUT)

helper/funcn.py

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# This file is part of the Compressor distribution.
2+
# Copyright (c) 2021 Danish_00
3+
#
4+
# This program is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, version 3.
7+
#
8+
# This program is distributed in the hope that it will be useful, but
9+
# WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
# General Public License for more details.
12+
#
13+
# License can be found in < https://github.com/1Danish-00/CompressorBot/blob/main/License> .
14+
15+
from .config import *
16+
17+
COUNT = []
18+
19+
uptime = dt.now()
20+
os.system("wget https://telegra.ph/file/75ee20ec8d8c8bba84f02.jpg")
21+
22+
if not os.path.isdir("downloads/"):
23+
os.mkdir("downloads/")
24+
if not os.path.isdir("encode/"):
25+
os.mkdir("encode/")
26+
if not os.path.isdir("thumb/"):
27+
os.mkdir("thumb/")
28+
29+
30+
def stdr(seconds: int) -> str:
31+
minutes, seconds = divmod(seconds, 60)
32+
hours, minutes = divmod(minutes, 60)
33+
if len(str(minutes)) == 1:
34+
minutes = "0" + str(minutes)
35+
if len(str(hours)) == 1:
36+
hours = "0" + str(hours)
37+
if len(str(seconds)) == 1:
38+
seconds = "0" + str(seconds)
39+
dur = (
40+
((str(hours) + ":") if hours else "00:")
41+
+ ((str(minutes) + ":") if minutes else "00:")
42+
+ ((str(seconds)) if seconds else "")
43+
)
44+
return dur
45+
46+
47+
def ts(milliseconds: int) -> str:
48+
seconds, milliseconds = divmod(int(milliseconds), 1000)
49+
minutes, seconds = divmod(seconds, 60)
50+
hours, minutes = divmod(minutes, 60)
51+
days, hours = divmod(hours, 24)
52+
tmp = (
53+
((str(days) + "d, ") if days else "")
54+
+ ((str(hours) + "h, ") if hours else "")
55+
+ ((str(minutes) + "m, ") if minutes else "")
56+
+ ((str(seconds) + "s, ") if seconds else "")
57+
+ ((str(milliseconds) + "ms, ") if milliseconds else "")
58+
)
59+
return tmp[:-2]
60+
61+
62+
def hbs(size):
63+
if not size:
64+
return ""
65+
power = 2 ** 10
66+
raised_to_pow = 0
67+
dict_power_n = {0: "B", 1: "K", 2: "M", 3: "G", 4: "T", 5: "P"}
68+
while size > power:
69+
size /= power
70+
raised_to_pow += 1
71+
return str(round(size, 2)) + " " + dict_power_n[raised_to_pow] + "B"
72+
73+
74+
async def progress(current, total, event, start, type_of_ps, file=None):
75+
now = time.time()
76+
diff = now - start
77+
if round(diff % 10.00) == 0 or current == total:
78+
percentage = current * 100 / total
79+
speed = current / diff
80+
time_to_completion = round((total - current) / speed) * 1000
81+
progress_str = "`[{0}{1}] {2}%`\n\n".format(
82+
"".join(["𒊹︎︎︎" for i in range(math.floor(percentage / 5))]),
83+
"".join(["●" for i in range(20 - math.floor(percentage / 5))]),
84+
round(percentage, 2),
85+
)
86+
tmp = (
87+
progress_str
88+
+ "`{0} of {1}`\n\n`✦ Speed: {2}/s`\n\n`✦ ETA: {3}`\n\n".format(
89+
hbs(current),
90+
hbs(total),
91+
hbs(speed),
92+
ts(time_to_completion),
93+
)
94+
)
95+
if file:
96+
await event.edit(
97+
"`✦ {}`\n\n`File Name: {}`\n\n{}".format(type_of_ps, file, tmp)
98+
)
99+
else:
100+
await event.edit("`✦ {}`\n\n{}".format(type_of_ps, tmp))
101+
102+
103+
async def genss(file):
104+
process = subprocess.Popen(
105+
["mediainfo", file, "--Output=JSON"],
106+
stdout=subprocess.PIPE,
107+
stderr=subprocess.STDOUT,
108+
)
109+
stdout, stderr = process.communicate()
110+
out = stdout.decode().strip()
111+
z = json.loads(out)
112+
p = z["media"]["track"][0]["Duration"]
113+
return int(p.split(".")[-2])
114+
115+
116+
async def duration_s(file):
117+
tsec = await genss(file)
118+
x = round(tsec / 5)
119+
y = round(tsec / 5 + 60)
120+
pin = stdr(x)
121+
if y < tsec:
122+
pon = stdr(y)
123+
else:
124+
pon = stdr(tsec)
125+
return pin, pon
126+
127+
128+
def code(data):
129+
key = (
130+
requests.post("https://nekobin.com/api/documents", json={"content": data})
131+
.json()
132+
.get("result")
133+
.get("key")
134+
)
135+
return key
136+
137+
138+
def decode(key):
139+
a = requests.get(f"https://nekobin.com/raw/{key}")
140+
return a.text
141+
142+
143+
async def skip(e):
144+
wah = e.pattern_match.group(1).decode("UTF-8")
145+
wh = decode(wah)
146+
out, dl, thum, dtime = wh.split(";")
147+
try:
148+
os.remove(dl)
149+
os.remove(out)
150+
COUNT.remove(e.sender_id)
151+
except:
152+
pass
153+
return await e.delete()

0 commit comments

Comments
 (0)