Skip to content

Commit

Permalink
v 0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
1Danish-00 committed Mar 23, 2021
0 parents commit 1a54d7d
Show file tree
Hide file tree
Showing 15 changed files with 1,612 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.9.2-slim-buster
RUN mkdir /bot && chmod 777 /bot
WORKDIR /bot
ENV DEBIAN_FRONTEND=noninteractive
RUN apt -qq update && apt -qq install -y git wget pv jq wget python3-dev ffmpeg mediainfo && pip3 install python-decouple telethon requests
COPY . .
CMD ["bash","run.sh"]
674 changes: 674 additions & 0 deletions License

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bot: python3 start.py
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div dir="ltr" style="text-align: left;" trbidi="on">
<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;">
𝕍𝕚𝕕𝕖𝕠 ℂ𝕆𝕄ℙℝ𝔼𝕊𝕊𝕆ℝ 𝔹𝕆𝕋</h3>
<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;">
ᴍᴜʟᴛɪғᴜɴᴄᴛɪᴏɴ ǫᴜᴀʟɪᴛʏ ᴄᴏᴍᴘʀᴇssᴏʀ</div>
<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;">
<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>
31 changes: 31 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "CompressorBot",
"description": "A Normal Telegram Bot Which can Compress/encode/ Generate Samples of videos.",
"logo": " #https://telegra.ph/file/75ee20ec8d8c8bba84f02.jpg",
"keywords": ["Telegram","python", "Video","Compressor","Encoder"],
"repository": "https://github.com/1Danish-00/CompressorBot",
"success_url": "https://t.me/danish_00",
"stack": "container",
"env": {
"APP_ID": {
"description": "You api id, from my.telegram.org or @apiScrapperRoBot.",
"value": ""
},
"API_HASH": {
"description": "You api hash, from my.telegram.org or @apiScrapperRoBot.",
"value": ""
},
"BOT_TOKEN": {
"description": "Make a bot from @BotFather, and enter it's api token here.",
"value": ""
},
"OWNER_ID": {
"description": "Get ur Id Of Telegram nd Paste Here.",
"value": ""
},
"LOG_CHANNEL": {
"description": "Create a private group. Add @missrose_bot and your bot. Do /id. Paste that here",
"value": ""
}
}
}
40 changes: 40 additions & 0 deletions helper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This file is part of the Compressor distribution.
# Copyright (c) 2021 Danish_00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# License can be found in < https://github.com/1Danish-00/CompressorBot/blob/main/License> .


import os
import re
import io
import sys
import math
import glob
import time
import json
import shutil
import asyncio
import inspect
import requests
import traceback
import subprocess
import telethon.utils
from pathlib import Path
from decouple import config
from datetime import datetime as dt

from telethon.sessions import StringSession
from telethon.utils import get_display_name
from telethon.tl.functions.users import GetFullUserRequest
from logging import basicConfig, getLogger, INFO, DEBUG, warning
from telethon.tl.functions.messages import ExportChatInviteRequest as cl
from telethon import TelegramClient, events, Button, errors, functions, types
1 change: 1 addition & 0 deletions helper/_get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .devtools import *
27 changes: 27 additions & 0 deletions helper/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This file is part of the Compressor distribution.
# Copyright (c) 2021 Danish_00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# License can be found in < https://github.com/1Danish-00/CompressorBot/blob/main/License> .

from . import *

try:
APP_ID = config("APP_ID", cast=int)
API_HASH = config("API_HASH")
BOT_TOKEN = config("BOT_TOKEN")
OWNER = config("OWNER_ID", default=1322549723, cast=int)
LOG = config("LOG_CHANNEL", cast=int)
except Exception as e:
LOGS.info("Environment vars Missing")
LOGS.info("something went wrong")
LOGS.info(str(e))
exit(1)
95 changes: 95 additions & 0 deletions helper/devtools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# This file is part of the Compressor distribution.
# Copyright (c) 2021 Danish_00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# License can be found in < https://github.com/1Danish-00/CompressorBot/blob/main/License> .

from .stuff import *


async def eval(event):
if event.sender_id != OWNER:
return
await event.reply("Processing ...")
cmd = event.text.split(" ", maxsplit=1)[1]
old_stderr = sys.stderr
old_stdout = sys.stdout
redirected_output = sys.stdout = io.StringIO()
redirected_error = sys.stderr = io.StringIO()
stdout, stderr, exc = None, None, None
try:
await aexec(cmd, event)
except Exception:
exc = traceback.format_exc()
stdout = redirected_output.getvalue()
stderr = redirected_error.getvalue()
sys.stdout = old_stdout
sys.stderr = old_stderr
evaluation = ""
if exc:
evaluation = exc
elif stderr:
evaluation = stderr
elif stdout:
evaluation = stdout
else:
evaluation = "Success"
final_output = "**EVAL**: `{}` \n\n **OUTPUT**: \n`{}` \n".format(cmd, evaluation)
if len(final_output) > 4095:
with io.BytesIO(str.encode(final_output)) as out_file:
out_file.name = "eval.text"
await event.client.send_file(
event.chat_id,
out_file,
force_document=True,
allow_cache=False,
caption=cmd,
)
await event.delete()
else:
await event.reply(final_output)


async def aexec(code, event):
exec(f"async def __aexec(event): " + "".join(f"\n {l}" for l in code.split("\n")))
return await locals()["__aexec"](event)


async def bash(event):
if event.sender_id != OWNER:
return
cmd = event.text.split(" ", maxsplit=1)[1]
process = await asyncio.create_subprocess_shell(
cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await process.communicate()
e = stderr.decode()
if not e:
e = "No Error"
o = stdout.decode()
if not o:
o = "**Tip**: \n`If you want to see the results of your code, I suggest printing them to stdout.`"
else:
_o = o.split("\n")
o = "`\n".join(_o)
OUTPUT = f"**QUERY:**\n__Command:__\n`{cmd}` \n__PID:__\n`{process.pid}`\n\n**stderr:** \n`{e}`\n**Output:**\n{o}"
if len(OUTPUT) > 4095:
with io.BytesIO(str.encode(OUTPUT)) as out_file:
out_file.name = "exec.text"
await event.client.send_file(
event.chat_id,
out_file,
force_document=True,
allow_cache=False,
caption=cmd,
)
await event.delete()
await event.reply(OUTPUT)
153 changes: 153 additions & 0 deletions helper/funcn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# This file is part of the Compressor distribution.
# Copyright (c) 2021 Danish_00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# License can be found in < https://github.com/1Danish-00/CompressorBot/blob/main/License> .

from .config import *

COUNT = []

uptime = dt.now()
os.system("wget https://telegra.ph/file/75ee20ec8d8c8bba84f02.jpg")

if not os.path.isdir("downloads/"):
os.mkdir("downloads/")
if not os.path.isdir("encode/"):
os.mkdir("encode/")
if not os.path.isdir("thumb/"):
os.mkdir("thumb/")


def stdr(seconds: int) -> str:
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
if len(str(minutes)) == 1:
minutes = "0" + str(minutes)
if len(str(hours)) == 1:
hours = "0" + str(hours)
if len(str(seconds)) == 1:
seconds = "0" + str(seconds)
dur = (
((str(hours) + ":") if hours else "00:")
+ ((str(minutes) + ":") if minutes else "00:")
+ ((str(seconds)) if seconds else "")
)
return dur


def ts(milliseconds: int) -> str:
seconds, milliseconds = divmod(int(milliseconds), 1000)
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
days, hours = divmod(hours, 24)
tmp = (
((str(days) + "d, ") if days else "")
+ ((str(hours) + "h, ") if hours else "")
+ ((str(minutes) + "m, ") if minutes else "")
+ ((str(seconds) + "s, ") if seconds else "")
+ ((str(milliseconds) + "ms, ") if milliseconds else "")
)
return tmp[:-2]


def hbs(size):
if not size:
return ""
power = 2 ** 10
raised_to_pow = 0
dict_power_n = {0: "B", 1: "K", 2: "M", 3: "G", 4: "T", 5: "P"}
while size > power:
size /= power
raised_to_pow += 1
return str(round(size, 2)) + " " + dict_power_n[raised_to_pow] + "B"


async def progress(current, total, event, start, type_of_ps, file=None):
now = time.time()
diff = now - start
if round(diff % 10.00) == 0 or current == total:
percentage = current * 100 / total
speed = current / diff
time_to_completion = round((total - current) / speed) * 1000
progress_str = "`[{0}{1}] {2}%`\n\n".format(
"".join(["𒊹︎︎︎" for i in range(math.floor(percentage / 5))]),
"".join(["●" for i in range(20 - math.floor(percentage / 5))]),
round(percentage, 2),
)
tmp = (
progress_str
+ "`{0} of {1}`\n\n`✦ Speed: {2}/s`\n\n`✦ ETA: {3}`\n\n".format(
hbs(current),
hbs(total),
hbs(speed),
ts(time_to_completion),
)
)
if file:
await event.edit(
"`✦ {}`\n\n`File Name: {}`\n\n{}".format(type_of_ps, file, tmp)
)
else:
await event.edit("`✦ {}`\n\n{}".format(type_of_ps, tmp))


async def genss(file):
process = subprocess.Popen(
["mediainfo", file, "--Output=JSON"],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
stdout, stderr = process.communicate()
out = stdout.decode().strip()
z = json.loads(out)
p = z["media"]["track"][0]["Duration"]
return int(p.split(".")[-2])


async def duration_s(file):
tsec = await genss(file)
x = round(tsec / 5)
y = round(tsec / 5 + 60)
pin = stdr(x)
if y < tsec:
pon = stdr(y)
else:
pon = stdr(tsec)
return pin, pon


def code(data):
key = (
requests.post("https://nekobin.com/api/documents", json={"content": data})
.json()
.get("result")
.get("key")
)
return key


def decode(key):
a = requests.get(f"https://nekobin.com/raw/{key}")
return a.text


async def skip(e):
wah = e.pattern_match.group(1).decode("UTF-8")
wh = decode(wah)
out, dl, thum, dtime = wh.split(";")
try:
os.remove(dl)
os.remove(out)
COUNT.remove(e.sender_id)
except:
pass
return await e.delete()
Loading

0 comments on commit 1a54d7d

Please sign in to comment.