Skip to content

Commit

Permalink
optimizing initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
rking32 committed Jul 19, 2020
1 parent 9357c10 commit 76a4f95
Show file tree
Hide file tree
Showing 21 changed files with 771 additions and 165 deletions.
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,16 @@ dmypy.json
# Pyre type checker
.pyre/

#configfile
# config files
config.ini
config.env
.vscode/settings.json
.vscode/
*.session
rn
log.txt
gen
unknown_errors.txt
logs/
bin/
resources/base_profile_pic.jpg
resources/mdfy_profile_pic.jpg
pictest.py
dev
resources/MutantAcademyBB.ttf
72 changes: 37 additions & 35 deletions config.env.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash
#
# Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >.
#
# This file is part of < https://github.com/UsergeTeam/Userge > project,
Expand All @@ -8,124 +10,124 @@


# Remove this line first before doing anything else
_____REMOVE_____THIS_____LINE_____ = True
_____REMOVE_____THIS_____LINE_____=true


# Get them from https://my.telegram.org/
API_ID = ""
API_HASH = ""
API_ID=""
API_HASH=""


# Get it by running `bash genStr` command
HU_STRING_SESSION = ""
HU_STRING_SESSION=""


# Mongodb url from https://cloud.mongodb.com/
DATABASE_URL = ""
DATABASE_URL=""


# Googel Drive API Keys from https://console.developers.google.com/
G_DRIVE_CLIENT_ID = ""
G_DRIVE_CLIENT_SECRET = ""
G_DRIVE_CLIENT_ID=""
G_DRIVE_CLIENT_SECRET=""


# Set True if it is TeamDrive
G_DRIVE_IS_TD = False
# Set true if it is TeamDrive
G_DRIVE_IS_TD=false


# Telegram Log Channel ID
LOG_CHANNEL_ID = ""
LOG_CHANNEL_ID=""


# Set True if your like to use unofficial plugins
LOAD_UNOFFICIAL_PLUGINS = False
# Set true if your like to use unofficial plugins
LOAD_UNOFFICIAL_PLUGINS=false


# ----------- OPTIONAL ----------- #


# Get this from https://t.me/botfather if you like to use userge as a bot
BOT_TOKEN = ""
BOT_TOKEN=""


# Your user_id if you are gonna use userge as a bot
OWNER_ID = ""
OWNER_ID=""


# Userbot Workers Count : Default = 4
WORKERS = 4
# Userbot Workers Count : Default=4
WORKERS=4


# Index link for gdrive
G_DRIVE_INDEX_LINK = ""
G_DRIVE_INDEX_LINK=""


# Set name to your working directory
DOWN_PATH = "downloads/"
DOWN_PATH="downloads/"


# Your Languge ( ex: if english => 'en' )
PREFERRED_LANGUAGE = ""
PREFERRED_LANGUAGE=""


# get API Key from 'https://free.currencyconverterapi.com/'
CURRENCY_API = ""
CURRENCY_API=""


# get API key for OCR module 'http://eepurl.com/bOLOcf'
OCR_SPACE_API_KEY = ""
OCR_SPACE_API_KEY=""


# add default city for weather
WEATHER_DEFCITY = ""
WEATHER_DEFCITY=""


# SpamWatch API get it from @SpamWatch in Telegram
SPAM_WATCH_API = ""
SPAM_WATCH_API=""


# Toggle API Auto Bans, Active if set to True
ANTISPAM_SENTRY = False
# Toggle API Auto Bans, Active if set to true
ANTISPAM_SENTRY=false


# Weather API get it from 'https://openweathermap.org/'
OPEN_WEATHER_MAP = ""
OPEN_WEATHER_MAP=""


# RemoveBg API Key get it from 'https://www.remove.bg/api'
REMOVE_BG_API_KEY = ""
REMOVE_BG_API_KEY=""


# GDrive Folder ID
G_DRIVE_PARENT_ID = ""
G_DRIVE_PARENT_ID=""


# set command prefix
CMD_TRIGGER = "."
CMD_TRIGGER="."


# set command prefix for SUDO users
SUDO_TRIGGER = "!"
SUDO_TRIGGER="!"


# set this to your USERGE fork on GitHub
UPSTREAM_REPO = ""
UPSTREAM_REPO=""


# single character for finished progress
FINISHED_PROGRESS_STR = '█'
FINISHED_PROGRESS_STR=''


# single character for unfinished progress
UNFINISHED_PROGRESS_STR = '░'
UNFINISHED_PROGRESS_STR=''


# ----------- Only If Using Heroku ----------- #


# get a Heroku API key from http://dashboard.heroku.com/account
HEROKU_API_KEY = ""
HEROKU_API_KEY=""


# given app name to the heroku app
HEROKU_APP_NAME = ""
HEROKU_APP_NAME=""
10 changes: 9 additions & 1 deletion genStr
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#!/bin/bash
#
# Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >.
#
# This file is part of < https://github.com/UsergeTeam/Userge > project,
# and is released under the "GNU v3.0 License Agreement".
# Please see < https://github.com/uaudith/Userge/blob/master/LICENSE >
#
# All rights reserved.

python3 genStrSession.py
python3 genStrSession.py
184 changes: 184 additions & 0 deletions init/checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
#!/bin/bash
#
# Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >.
#
# This file is part of < https://github.com/UsergeTeam/Userge > project,
# and is released under the "GNU v3.0 License Agreement".
# Please see < https://github.com/uaudith/Userge/blob/master/LICENSE >
#
# All rights reserved.

_checkBashReq() {
log "Checking Bash Commands ..."
command -v jq &> /dev/null || quit "Required command : jq : could not be found !"
}

_checkPythonVersion() {
log "Checking Python Version ..."
test $(sed 's/\.//g' <<< $pVer) -lt 370 \
&& quit "You MUST have a python version of at least 3.7.0 !"
log "\tFound PYTHON - v$pVer ..."
}

_checkConfigFile() {
log "Checking Config File ..."
configPath="config.env"
if test -f $configPath; then
log "\tConfig file found : $configPath, Exporting ..."
set -a
. $configPath
set +a
test ${_____REMOVE_____THIS_____LINE_____:-fasle} = true \
&& quit "Please remove the line mentioned in the first hashtag from the config.sh file"
fi
}

_checkRequiredVars() {
log "Checking Required ENV Vars ..."
for var in API_ID API_HASH LOG_CHANNEL_ID DATABASE_URL; do
test -z ${!var} && quit "Required $var var !"
done
[[ -z $HU_STRING_SESSION && -z $BOT_TOKEN ]] && quit "Required HU_STRING_SESSION or BOT_TOKEN var !"
[[ -n $BOT_TOKEN && -z $OWNER_ID ]] && quit "Required OWNER_ID var !"
test -z $BOT_TOKEN && log "\t[HINT] >>> BOT_TOKEN not found ! (Disabling Advanced Loggings)"
}

_checkDefaultVars() {
replyLastMessage "Checking Default ENV Vars ..."
declare -rA def_vals=(
[WORKERS]=4
[ANTISPAM_SENTRY]=false
[PREFERRED_LANGUAGE]="en"
[DOWN_PATH]="downloads"
[UPSTREAM_REMOTE]="upstream"
[UPSTREAM_REPO]="https://github.com/UsergeTeam/Userge"
[LOAD_UNOFFICIAL_PLUGINS]=false
[G_DRIVE_IS_TD]=true
[CMD_TRIGGER]="."
[SUDO_TRIGGER]="!"
[FINISHED_PROGRESS_STR]=""
[UNFINISHED_PROGRESS_STR]=""
)
for key in ${!def_vals[@]}; do
set -a
test -z ${!key} && eval $key=${def_vals[$key]}
set +a
done
DOWN_PATH=${DOWN_PATH%/}/
[[ -n $HEROKU_API_KEY && -n $HEROKU_APP_NAME ]] \
&& declare -gx HEROKU_GIT_URL="https://api:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git"
for var in ANTISPAM_SENTRY G_DRIVE_IS_TD LOAD_UNOFFICIAL_PLUGINS; do
eval $var=$(tr "[:upper:]" "[:lower:]" <<< ${!var})
done
local nameAndUName=$(grep -oP "(?<=\/\/)(.+)(?=\@)" <<< $DATABASE_URL)
DATABASE_URL=$(sed 's/$nameAndUName/$(printf "%q\n" $nameAndUName)/' <<< $DATABASE_URL)
}

_checkDatabase() {
editLastMessage "Checking DATABASE_URL ..."
local err=$(runPythonCode '
import pymongo
try:
pymongo.MongoClient("'$DATABASE_URL'").list_database_names()
except Exception as e:
print(e)
')
[[ $err ]] && quit "pymongo response > $err" || log "\tpymongo response > {status : 200}"
}

_checkTriggers() {
editLastMessage "Checking TRIGGERS ..."
test $CMD_TRIGGER = $SUDO_TRIGGER \
&& quit "Invalid SUDO_TRIGGER!, You can't use $CMD_TRIGGER as SUDO_TRIGGER"
}

_checkPaths() {
editLastMessage "Checking Paths ..."
for path in $DOWN_PATH logs bin; do
test ! -d $path && {
log "\tCreating Path : ${path%/} ..."
mkdir -p $path
}
done
}

_checkBins() {
editLastMessage "Checking BINS ..."
declare -rA bins=(
[bin/megadown]="https://raw.githubusercontent.com/yshalsager/megadown/master/megadown"
[bin/cmrudl]="https://raw.githubusercontent.com/yshalsager/cmrudl.py/master/cmrudl.py"
)
for bin in ${!bins[@]}; do
test ! -f $bin && {
log "\tDownloading $bin ..."
curl -so $bin ${bins[$bin]}
}
done
}

_checkGit() {
editLastMessage "Checking GIT ..."
if test ! -d .git; then
if test -n $HEROKU_GIT_URL; then
replyLastMessage "\tClonning Heroku Git ..."
gitClone $HEROKU_GIT_URL tmp_git || quit "Invalid HEROKU_API_KEY or HEROKU_APP_NAME var !"
mv tmp_git/.git .
rm -rf tmp_git
else
replyLastMessage "\tInitializing Empty Git ..."
gitInit
fi
deleteLastMessage
fi
}

_checkUpstreamRepo() {
editLastMessage "Checking UPSTREAM_REPO ..."
grep -q $UPSTREAM_REMOTE < <(git remote) || addUpstream
replyLastMessage "\tFetching Data From UPSTREAM_REPO ..."
fetchUpstream || updateUpstream && fetchUpstream || quit "Invalid UPSTREAM_REPO var !"
deleteLastMessage
}

_checkUnoffPlugins() {
editLastMessage "Checking UnOfficial Plugins ..."
if test $LOAD_UNOFFICIAL_PLUGINS = true; then
editLastMessage "\tLoading UnOfficial Plugins ..."
replyLastMessage "\t\tClonning ..."
gitClone --depth=1 https://github.com/UsergeTeam/Userge-Plugins.git
editLastMessage "\t\tUpgrading PIP ..."
upgradePip
editLastMessage "\t\tInstalling Requirements ..."
installReq Userge-Plugins
editLastMessage "\t\tCleaning ..."
rm -rf userge/plugins/unofficial/
mv Userge-Plugins/plugins/ userge/plugins/unofficial/
cp -r Userge-Plugins/resources/* resources/
rm -rf Userge-Plugins/
deleteLastMessage
editLastMessage "\tUnOfficial Plugins Loaded Successfully !"
else
editLastMessage "\tUnOfficial Plugins Disabled !"
fi
sleep 1
deleteLastMessage
}

assertPrerequisites() {
_checkBashReq
_checkPythonVersion
_checkConfigFile
_checkRequiredVars
}

assertEnvironment() {
_checkDefaultVars
_checkDatabase
_checkTriggers
_checkPaths
_checkBins
_checkGit
_checkUpstreamRepo
_checkUnoffPlugins
}
Loading

0 comments on commit 76a4f95

Please sign in to comment.