Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxxRider authored May 5, 2021
1 parent a5f528c commit 0ab370e
Show file tree
Hide file tree
Showing 17 changed files with 1,016 additions and 1,076 deletions.
14 changes: 6 additions & 8 deletions tobrot/helper_funcs/admin_check.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from tobrot import AUTH_CHANNEL


async def AdminCheck(client, chat_id, user_id):
SELF = await client.get_chat_member(
chat_id=chat_id,
user_id=user_id
)
admin_strings = [
"creator",
"administrator"
]
chat = await client.get_chat(chat_id)
if chat.type == "private" and chat_id in AUTH_CHANNEL:
return True
SELF = await client.get_chat_member(chat_id=chat_id, user_id=user_id)
admin_strings = ["creator", "administrator"]
# https://git.colinshark.de/PyroBot/PyroBot/src/branch/master/pyrobot/modules/admin.py#L69
if SELF.status not in admin_strings:
return False
Expand Down
152 changes: 67 additions & 85 deletions tobrot/helper_funcs/cloneHelper.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
#This is code to clone the gdrive link using the gclone, all credit goes to the developer who has developed the rclone/glclone
# This is code to clone the gdrive link using the gclone, all credit goes to the developer who has developed the rclone/glclone
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# (c) gautamajay52
# (c) MaxxRider


import subprocess
import asyncio
import logging
import os
import re
import subprocess

import pyrogram.types as pyrogram
import requests

import logging
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
logging.getLogger("pyrogram").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)
LOGGER = logging.getLogger(__name__)

from tobrot import (
TG_MAX_FILE_SIZE,
EDIT_SLEEP_TIME_OUT,
DOWNLOAD_LOCATION,
DESTINATION_FOLDER,
RCLONE_CONFIG,
DOWNLOAD_LOCATION,
EDIT_SLEEP_TIME_OUT,
INDEX_LINK,
UPLOAD_AS_DOC
LOGGER,
RCLONE_CONFIG,
TG_MAX_FILE_SIZE,
UPLOAD_AS_DOC,
)


Expand All @@ -41,22 +34,20 @@ def __init__(self, mess):
self.lsg = ""
self.filee = ""
self.u_id = self.mess.from_user.id

self.dname = ""

def config(self):
with open(
'rclone.conf',
'a',
newline="\n",
encoding= 'utf-8'
) as fole:
fole.write("[DRIVE]\n")
fole.write(f"{RCLONE_CONFIG}")


if not os.path.exists("rclone.conf"):
with open("rclone.conf", "w+", newline="\n", encoding="utf-8") as fole:
fole.write(f"{RCLONE_CONFIG}")
if os.path.exists("rclone.conf"):
with open("rclone.conf", "r+") as file:
con = file.read()
self.dname = re.findall("\[(.*)\]", con)[0]

def get_id(self):
mes = self.mess
txt= mes.reply_to_message.text
txt = mes.reply_to_message.text
LOGGER.info(txt)
mess = txt.split(" ", maxsplit=1)
if len(mess) == 2:
Expand All @@ -69,8 +60,7 @@ def get_id(self):
LOGGER.info(self.g_id)
self.name = ""
return self.g_id, self.name



async def link_gen_size(self):
if self.name is not None:
_drive = ""
Expand All @@ -85,55 +75,46 @@ async def link_gen_size(self):
_ui = "/"
g_name = re.escape(self.name)
LOGGER.info(g_name)
destination = f'{DESTINATION_FOLDER}'

with open(
'filter1.txt',
'w+',
encoding= 'utf-8'
) as filter1:
print(f"+ {g_name}{_ui}\n- *",
file=filter1
)

destination = f"{DESTINATION_FOLDER}"

with open("filter1.txt", "w+", encoding="utf-8") as filter1:
print(f"+ {g_name}{_ui}\n- *", file=filter1)

g_a_u = [
'rclone',
'lsf',
'--config=./rclone.conf',
'-F',
'i',
"rclone",
"lsf",
"--config=./rclone.conf",
"-F",
"i",
"--filter-from=./filter1.txt",
f"{_flag}",
f'DRIVE:{destination}'
f"{self.dname}:{destination}",
]
LOGGER.info(g_a_u)
gau_tam = await asyncio.create_subprocess_exec(
*g_a_u,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE
*g_a_u, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
gau, tam = await gau_tam.communicate()
LOGGER.info(gau)
gautam = gau.decode("utf-8")
LOGGER.info(gautam)
LOGGER.info(tam.decode('utf-8'))
LOGGER.info(tam.decode("utf-8"))

if _drive == "folderba":
gautii = f"https://drive.google.com/folderview?id={gautam}"
else:
gautii = f"https://drive.google.com/file/d/{gautam}/view?usp=drivesdk"

LOGGER.info(gautii)
gau_link = re.search("(?P<url>https?://[^\s]+)", gautii).group("url")
LOGGER.info(gau_link)
button = []
button.append(
[
pyrogram.InlineKeyboardButton(
text=" 💥 GOOGLE DRIVE URL 💥 ",
url=f"{gau_link}"
text="🔮 CLOUD LINK", url=f"{gau_link}"
)
]
]
)
if INDEX_LINK:
if _flag == "--files-only":
Expand All @@ -142,59 +123,60 @@ async def link_gen_size(self):
indexurl = f"{INDEX_LINK}/{self.name}/"
tam_link = requests.utils.requote_uri(indexurl)
LOGGER.info(tam_link)
button.append([pyrogram.InlineKeyboardButton(text="⚡ INDEX LINK ⚡", url=f"{tam_link}")])
button.append(
[
pyrogram.InlineKeyboardButton(
text="💡 𝐈𝐧𝐝𝐞𝐱 𝐋𝐢𝐧𝐤", url=f"{tam_link}"
)
]
)
button_markup = pyrogram.InlineKeyboardMarkup(button)
msg = await self.lsg.edit_text(
f"<b>🤖: {_up} cloned successfully in your Cloud</b> <a href='tg://user?id={self.u_id}'>😁</a>\
\n<b>🔹Info</b>: Calculating...",
f"🐈: {_up} Cloned successfully in your Cloud <a href='tg://user?id={self.u_id}'>😊</a>\
\n📀 Info: Calculating...",
reply_markup=button_markup,
parse_mode="html"
parse_mode="html",
)
g_cmd = [
'rclone',
'size',
'--config=rclone.conf',
f'DRIVE:{destination}/{self.name}'
"rclone",
"size",
"--config=rclone.conf",
f"{self.dname}:{destination}/{self.name}",
]
LOGGER.info(g_cmd)
gaut_am = await asyncio.create_subprocess_exec(
*g_cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE
*g_cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
gaut, am = await gaut_am.communicate()
g_autam = gaut.decode("utf-8")
LOGGER.info(g_autam)
LOGGER.info(am.decode('utf-8'))
LOGGER.info(am.decode("utf-8"))
await asyncio.sleep(EDIT_SLEEP_TIME_OUT)
await msg.edit_text(
f"<b>🤖: {_up} cloned successfully in your Cloud</b> <a href='tg://user?id={self.u_id}'>😁</a>\
\n<b>🔹Info</b>:\n{g_autam}",
f"🐈: {_up} Cloned successfully in your Cloud <a href='tg://user?id={self.u_id}'>😊</a>\
\n📀 Info:\n{g_autam}",
reply_markup=button_markup,
parse_mode="html"
parse_mode="html",
)




async def gcl(self):
self.lsg = await self.mess.reply_text(f"<b>Cloning...you should wait...😒</b>")
destination = f'{DESTINATION_FOLDER}'
self.lsg = await self.mess.reply_text(f"Cloning...you should wait 🤒")
destination = f"{DESTINATION_FOLDER}"
idd = "{" f"{self.g_id}" "}"
cmd = [
"/app/gautam/gclone",
"copy",
"--config=rclone.conf",
"DRIVE:{"f"{self.g_id}""}",
f"DRIVE:{destination}/{self.name}",
f"{self.dname}:{idd}",
f"{self.dname}:{destination}/{self.name}",
"-v",
"--drive-server-side-across-configs",
"--transfers=16",
"--checkers=20"
"--checkers=20",
]
LOGGER.info(cmd)
pro = await asyncio.create_subprocess_exec(
*cmd,
stdout=asyncio.subprocess.PIPE,
stderr= asyncio.subprocess.PIPE
*cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
p, e = await pro.communicate()
self.out = p
Expand Down
16 changes: 2 additions & 14 deletions tobrot/helper_funcs/copy_similar_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,14 @@
# -*- coding: utf-8 -*-
# (c) Shrimadhav U K

# the logging things
import logging
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
logging.getLogger("pyrogram").setLevel(logging.WARNING)
LOGGER = logging.getLogger(__name__)


from shutil import copyfile
import os
import time
from shutil import copyfile


async def copy_file(input_file, output_dir):
output_file = os.path.join(
output_dir,
str(time.time()) + ".jpg"
)
output_file = os.path.join(output_dir, str(time.time()) + ".jpg")
# https://stackoverflow.com/a/123212/4723940
copyfile(input_file, output_file)
return output_file
Loading

0 comments on commit 0ab370e

Please sign in to comment.