Skip to content

Commit

Permalink
added speed
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmsj committed Aug 22, 2022
1 parent 004a6d7 commit b01719e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
7 changes: 3 additions & 4 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
add checkfail
make readme
improve oauth flow, preferably netlifyapp
errors :(
make tutorial
make tutorial/docs/readme
bypasser
search for files (with sorting options)
webapp for this thing
lst_changelog update @github raw, change embed (add field if new changelog) (db thingy)


DONE:
size cmd
make help cmd
log command
heroku stuff
heroku stuff
lst_changelog
5 changes: 5 additions & 0 deletions changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,10 @@
"title":"add changelog.json",
"description":"Make a file which shows recent changes to the bot",
"timestamp":1661179970
},
"10":{
"title":"added speed",
"description":"shows speed now while cloning",
"timestamp":1661182170
}
}
9 changes: 6 additions & 3 deletions cogs/_gd_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from cogs._helpers import embed,status_emb
# import asyncio
from discord import Message
from main import logger


class GoogleDrive:
def __init__(self, user_id,use_sa):
Expand Down Expand Up @@ -101,7 +103,7 @@ async def cloneFolder(self, name, local_path, folder_id, parent_id,msg:Message,t
pass
try:
self.copyFile(file.get('id'), parent_id)
emb = status_emb(transferred = self.transferred_size,current_file_name = file.get('name'),total_size=total_size)
emb = status_emb(transferred = self.transferred_size,current_file_name = file.get('name'),total_size=total_size,start_time=self.start_time)
await msg.edit(embed=emb)
new_id = parent_id
except Exception as err:
Expand All @@ -127,6 +129,7 @@ def create_directory(self, directory_name,**kwargs):

async def clone(self,msg:Message,link):
self.transferred_size = 0
self.start_time = time.time()
try:
file_id = self.getIdFromUrl(link)
except (IndexError, KeyError):
Expand All @@ -138,10 +141,10 @@ async def clone(self,msg:Message,link):
if meta.get("mimeType") == self.__G_DRIVE_DIR_MIME_TYPE:
dir_id = self.create_directory(meta.get('name'),parent_id=self.__parent_id)
result = await self.cloneFolder(meta.get('name'), meta.get('name'), meta.get('id'), dir_id,msg,total_size)
return embed(title="✅ Copied successfully.",description=f"[{meta.get('name')}]({self.__G_DRIVE_DIR_BASE_DOWNLOAD_URL.format(dir_id)}) ---- `{humanbytes(self.transferred_size)}`\n{'#️⃣'*19+'▶️'} 100 %",url=self.__G_DRIVE_DIR_BASE_DOWNLOAD_URL.format(dir_id))
return embed(title="✅ Copied successfully.",description=f"[{meta.get('name')}]({self.__G_DRIVE_DIR_BASE_DOWNLOAD_URL.format(dir_id)}) ---- `{humanbytes(self.transferred_size)}`\n{'#️⃣'*19+'▶️'} 100 % (`{humanbytes(int(self.transferred_size/(time.time()-self.start_time)))}/s avg`)",url=self.__G_DRIVE_DIR_BASE_DOWNLOAD_URL.format(dir_id))
else:
file = self.copyFile(meta.get('id'), self.__parent_id)
return embed(title="✅ Copied successfully.",description=f"[{file.get('name')}]({self.__G_DRIVE_BASE_DOWNLOAD_URL.format(file.get('id'))}) ---- `{humanbytes(int(meta.get('size')))}`\n{'#️⃣'*19+'▶️'} 100 %",url=self.__G_DRIVE_BASE_DOWNLOAD_URL.format(file.get('id')))
return embed(title="✅ Copied successfully.",description=f"[{file.get('name')}]({self.__G_DRIVE_BASE_DOWNLOAD_URL.format(file.get('id'))}) ---- `{humanbytes(int(meta.get('size')))}`\n{'#️⃣'*19+'▶️'} 100 % (`{humanbytes(int(int(meta.get('size'))/(time.time()-self.start_time)))}/s avg`)",url=self.__G_DRIVE_BASE_DOWNLOAD_URL.format(file.get('id')))
except Exception as err:
if isinstance(err, RetryError):
err = err.last_attempt.exception()
Expand Down
7 changes: 4 additions & 3 deletions cogs/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import zipfile
import shutil
import os
import time


def is_allowed():
Expand Down Expand Up @@ -60,10 +61,10 @@ def show_progress_still(current:int,total:int,width:int):
hashblocks = 0
return "#️⃣"* hashblocks + "▶️" + "🟦"*(width-hashblocks-1)

def status_emb(transferred:int,current_file_name,total_size:int):
em = discord.Embed(title="📺 Status",color=discord.Color.green(),url="https://github.com/jsmsj/gdriveclonebot")
def status_emb(transferred:int,current_file_name,total_size:int,start_time):
em = discord.Embed(title="📺 Status : Copying...",color=discord.Color.green(),url="https://github.com/jsmsj/gdriveclonebot")
em.set_footer(text="Made with 💖 by jsmsj")
em.description = f"Current File: `{current_file_name}`\nStatus: Copying...📚\nCopied: {humanbytes(transferred)} of {humanbytes(total_size)}\n\n{show_progress_still(transferred,total_size,20)}🏁 {round(transferred*100/total_size,3)} %"
em.description = f"Current File: `{current_file_name}`\nStatus: Copying...📚\nCopied: {humanbytes(transferred)} of {humanbytes(total_size)} (`{humanbytes(int(transferred/(time.time()-start_time)))}/s`)\n\n{show_progress_still(transferred,total_size,20)}🏁 {round(transferred*100/total_size,3)} %"
return em

def zip_sas_cre():
Expand Down
7 changes: 6 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import cogs._config
import shutil,os
from cogs._helpers import embed

if os.path.exists('log.txt'):
with open('log.txt', 'r+') as f:
Expand All @@ -25,7 +26,7 @@ async def on_ready():
print("Bot is ready!")

@bot.event
async def on_command_error(ctx,error):
async def on_command_error(ctx:commands.Context,error):
if hasattr(ctx.command, 'on_error'):
return
if isinstance(error,commands.CommandNotFound):
Expand All @@ -34,6 +35,10 @@ async def on_command_error(ctx,error):
await ctx.send(f"You do not have permission to run this command.\nOR\nYou have not authorized the bot with your account. Run `{cogs._config.prefix}auth` to authorize.\nOR\nYou are using a command related to service accounts, and have not authorized for it. Use `{cogs._config.prefix}authsa` to authorize for service accounts.")
else:
logger.warning(error)
_file=None
if os.path.exists('log.txt'):
_file = discord.File('log.txt')
await ctx.send(embed=embed(f'Error | {ctx.command.name}',f'An error occured, kindly report it to jsmsj#5252.\n```py\n{error}\n```\nHere is the attached logfile.')[0],file=_file)

if __name__ == '__main__':
# When running this file, if it is the 'main' file
Expand Down

0 comments on commit b01719e

Please sign in to comment.