Skip to content

Commit

Permalink
add readme etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmsj committed Aug 23, 2022
1 parent d989e56 commit 4f91cbf
Show file tree
Hide file tree
Showing 10 changed files with 383 additions and 128 deletions.
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Not a mirror bot
###### Now that being out of the way, lets start:
---
## What is it ?

This is a clone bot, which clones google drive urls, to your own Teamdrive or Personal Google Drive.

## How it works ?

The bot requires your google drive authentication to clone the files to which you have access. It also clones public google drive links, moreover you can add your service accounts, to increase the limit of cloning public urls

## Features:

### Clone google drive links
- Continue reading to see which links can the bot clone

### Service Accounts
- Features a `quickstart` command for the newbies to quickly generate 100 service accounts.
- Featues commands like `saemails` , `downloadsazip`, `createsas` etc. which enables users to downlad that emails.txt file (those who know, know), download zip file of service accounts and even create service accounts for a given project id.

### Database
- Has a mongodb database, which stores service accounts and their emails, so that the bot doesn't ping the google api everytime it uses them. [because for a given project, google api only allows the service account to be downloaded 10 times.]
- Also used to store the default location for cloning (changable via `set_folder` command.)



## Which links can it clone ?

| From | To | Can Clone ? | Using S.A. | Limit | Bot Command |
| ------------ | ------------ | ------------ | ------------ | ------------ | ------------ |
| Public Url (**everyone has access**) | Public/Private folder (**you have uploading access** but S.A. do not) | yes |no| 750GB |`prefix privclone`|
| Public Url (**everyone has access**) | Public/Private folder (**S.A. have uploading access**) | yes |yes| (750 x no. of S.A.) GB |`prefix pubclone`|
| Public Url (**everyone has access**) | Public/Private folder (neither have uploading access) | no |-| - |-|
| Private Url** (**you have access**) | Public/Private folder (**you have uploading access** but S.A. do not) | yes |no| 750GB |`prefix privclone`|
| Private Url (**S.A. have access**) | Public/Private folder (**S.A. have uploading access**) | yes |yes| (750 x no. of S.A.) GB |`prefix pubclone`|
| Private Url (you do not have access) | Public/Private folder | no |-| - |-|
---

> `S.A.` stands for "Service Accounts"
>
> All S.A. have access of public links (everyone can access)
>
> ** For example you are a part of a teamdrive (but that teamdrive does not have your S.A.) and you need to clone a folder from it to your personal drive or teamdrive.
>
> `no.` stands for "number of"
>
> The Bot can clone to Teamdrive (Shared drive) if and only if you or your S.A. have uploading access.
# How to deploy ?

video coming soon
<p><a href="https://www.google.com"> <img src="https://img.shields.io/badge/See%20Video-black?style=for-the-badge&logo=YouTube" width="160""/></a></p>








5 changes: 5 additions & 0 deletions changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,10 @@
"title":"logging added",
"description":"Added logging to various modules and added errors.",
"timestamp":1661184750
},
"12":{
"title":"add readme etc.",
"description":"Added a readme file, and updated the site to show changelog and readme",
"timestamp":1661257002
}
}
8 changes: 6 additions & 2 deletions cogs/authorize.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Imports"""
import discord
import asyncio
from discord.ext import commands
import cogs._db_helpers as db
from httplib2 import Http
Expand Down Expand Up @@ -51,7 +52,10 @@ async def auth(self,ctx):
logger.error(e,exc_info=True)
em,view = embed("Error",f"```py\n{e}\n```",None)
return await ctx.reply(embed=em,view=view)
msg = await self.bot.wait_for('message', check=lambda message : message.author == ctx.author and message.channel == ctx.channel, timeout=120)
try:
msg = await self.bot.wait_for('message', check=lambda message : message.author == ctx.author and message.channel == ctx.channel, timeout=120)
except asyncio.TimeoutError:
return await ctx.send(embed=embed('Error | Timed out','You did not respond in time. Re run the command and try to respond under 120 seconds.')[0])
token = msg.content
WORD = len(token)
if WORD == 62 and token[1] == "/":
Expand All @@ -77,7 +81,7 @@ async def auth(self,ctx):
@commands.command(description=f'Used to revoke your Google Drive connected with the bot.\n`{cogs._config.prefix}revoke`')
async def revoke(self,ctx):
db.delete_creds(ctx.author.id)
em = embed(f"🔓 Revoked current logged in account successfully.","Use `{cogs._config.prefix}auth` to authenticate again and use this bot.",None)[0]
em = embed("🔓 Revoked current logged in account successfully.",f"Use `{cogs._config.prefix}auth` to authenticate again and use this bot.",None)[0]
await ctx.send(embed=em)

def setup(bot):
Expand Down
6 changes: 5 additions & 1 deletion cogs/serviceaccs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import urllib
import requests
import os,shutil
import asyncio

import discord
from discord.ext import commands
Expand Down Expand Up @@ -59,7 +60,10 @@ async def authsa(self,ctx):
em,view = embed(title="🧾 Service Accounts",description=f"Visit the following URL and the authorise. You will be redirected to a error page. That page's url would be something like: https://localhost:1/XXXXXXXXX\nCopy that url and send here within 2 minutes.\n\n{auth_url}",url=auth_url)
# em,view = embed(title="🧾 Service Accounts",description=f"Visit the following URL and the authorise. Make sure to select all the scopes, copy the code and send it here within 2 minutes.\n\n{auth_url}",url=auth_url)
await ctx.send(embed=em,view=view)
msg:discord.Message = await self.bot.wait_for('message', check=lambda message : message.author == ctx.author and message.channel == ctx.channel, timeout=120)
try:
msg:discord.Message = await self.bot.wait_for('message', check=lambda message : message.author == ctx.author and message.channel == ctx.channel, timeout=120)
except asyncio.TimeoutError:
return await ctx.send(embed=embed('Error | Timed out','You did not respond in time. Re run the command and try to respond under 120 seconds.')[0])
sent_message = await ctx.reply("🕵️**Checking the received code...**")
try:
redir_url = msg.content
Expand Down
2 changes: 1 addition & 1 deletion docs/auth.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<meta name="description" content="" />
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
<script src="main.js"></script>
<script src="auth.js"></script>
<!-- <link rel="icon" href="img/favicon.png"> -->
</head>
<body class = "bg-secondary" onload="fillTextArea()">
Expand Down
122 changes: 122 additions & 0 deletions docs/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
function getAllUrlParams(url) {

// get query string from url (optional) or window
var queryString = url ? url.split('?')[1] : window.location.search.slice(1);

// we'll store the parameters here
var obj = {};

// if query string exists
if (queryString) {

// stuff after # is not part of query string, so get rid of it
queryString = queryString.split('#')[0];

// split our query string into its component parts
var arr = queryString.split('&');

for (var i = 0; i < arr.length; i++) {
// separate the keys and the values
var a = arr[i].split('=');

// set parameter name and value (use 'true' if empty)
var paramName = a[0];
var paramValue = typeof (a[1]) === 'undefined' ? true : a[1];

// (optional) keep case consistent
paramName = paramName.toLowerCase();
if (typeof paramValue === 'string') paramValue = paramValue.toLowerCase();

// if the paramName ends with square brackets, e.g. colors[] or colors[2]
if (paramName.match(/\[(\d+)?\]$/)) {

// create key if it doesn't exist
var key = paramName.replace(/\[(\d+)?\]/, '');
if (!obj[key]) obj[key] = [];

// if it's an indexed array e.g. colors[2]
if (paramName.match(/\[\d+\]$/)) {
// get the index value and add the entry at the appropriate position
var index = /\[(\d+)\]/.exec(paramName)[1];
obj[key][index] = paramValue;
} else {
// otherwise add the value to the end of the array
obj[key].push(paramValue);
}
} else {
// we're dealing with a string
if (!obj[paramName]) {
// if it doesn't exist, create property
obj[paramName] = paramValue;
} else if (obj[paramName] && typeof obj[paramName] === 'string'){
// if property does exist and it's a string, convert it to an array
obj[paramName] = [obj[paramName]];
obj[paramName].push(paramValue);
} else {
// otherwise add the property
obj[paramName].push(paramValue);
}
}
}
}

return obj;
}

function allpermutations(inputArr) {
var results = [];

function permute(arr, memo) {
var cur, memo = memo || [];

for (var i = 0; i < arr.length; i++) {
cur = arr.splice(i, 1);
if (arr.length === 0) {
results.push(memo.concat(cur));
}
permute(arr.slice(), memo.concat(cur));
arr.splice(i, 0, cur[0]);
}

return results;
}

return permute(inputArr);
}

function get_auth_code(url){
dict = getAllUrlParams(url)
const all_perms = JSON.stringify(allpermutations(["https://www.googleapis.com/auth/drive","https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/iam"]))
scopes__ = JSON.stringify(decodeURIComponent(dict.scope).split(" "))
if (all_perms.indexOf(scopes__) === -1){
var scope = false
}
else{
var scope = true
}
if (Object.keys(dict).length === 0){
return "Kindly go back and re-run the authorize command."
}
else if (scope){
return decodeURIComponent(dict.code)
}
else if (decodeURIComponent(dict.error)){
return "Error Access Denied"
}
else{
console.log(dict)
return "You did not check all the scopes! OR an error occured, Report it to jsmsj#5252 on Discord"
}
}

function fillTextArea(){
const txtarea = document.getElementById('code')
txtarea.innerHTML = get_auth_code()
}

function CopyText(id) {
var copyText = document.getElementById(id)
copyText.select();
copyText.setSelectionRange(0, 99999);
navigator.clipboard.writeText(copyText.value);
}
76 changes: 76 additions & 0 deletions docs/changelog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Changelog | GdriveCloneBot</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="" />
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
<!-- <link rel="icon" href="img/favicon.png"> -->
</head>
<body class = "text-bg-secondary">
<div class="text-bg-dark p-4 text-center h2">
<a class="navbar-brand" href="#">
<img src="./img/gdrivelogo.png" alt="" width="33" height="30">
</a>
Google Drive Clone Bot
<a class="navbar-brand" href="#">
<img src="./img/discordlogo.png" alt="" width="36" height="36">
</a>
</div>
<div class="container" id="maingrid">
<div class="row text-center h5 justify-content-center">
<div class="col-3">
<div class="list-group list-group-horizontal">
<a href="./index.html" class="list-group-item list-group-item-dark" style="width:100%;">Home</a>
</div>
</div>
<div class="col-3">
<div class="list-group list-group-horizontal">
<a href="#" class="list-group-item list-group-item-dark" style="width:100%;">Video Tutorial</a>
</div>
</div>
<div class="col-3">
<div class="list-group list-group-horizontal">
<a href="https://github.com/jsmsj/GdriveCloneBot" target="_blank" class="list-group-item list-group-item-dark" style="width:100%;">Github Repository</a>
</div>
</div>
</div>
<br>
<div class="row text-center h1 justify-content-center text-light">
<div class="col">
Changelog
</div>
</div>
<div class="row justify-content-center m-2">
<div class="col-1 h3">
S. No.
</div>
<div class="col-3 h3">
Title
</div>
<div class="col h3">
Description
</div>
<div class="col-3 h3 text-end">
Timestamp
</div>
</div>
</div>
<div class="position-absolute bottom-0 end-0 table-responsive">
<table class="table table-dark table-striped">
<tr>
<td>
<button type="button" class="btn btn-outline-info">
<a class="navbar-brand" href="https://www.github.com/jsmsj" target="_blank" rel="noopener noreferrer">
<img src="./img/githublogo.png" alt="" width="25" height="25">
&nbsp;jsmsj
</a>
</button>
</td>
</table>
</div>
<script src="changelog.js"></script>
</body>
</html>
Loading

0 comments on commit 4f91cbf

Please sign in to comment.