Skip to content

Commit

Permalink
optimize genStr and restart
Browse files Browse the repository at this point in the history
  • Loading branch information
rking32 committed May 26, 2020
1 parent c8e1c90 commit 35afc66
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

# Userge 🔥

[![Build Status](https://travis-ci.com/UsergeTeam/Userge.svg?branch=dev)](https://travis-ci.com/UsergeTeam/Userge) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/9ff2867320b049b99a4a77285bb03cc4)](https://www.codacy.com/gh/UsergeTeam/Userge?utm_source=github.com&utm_medium=referral&utm_content=UsergeTeam/Userge&utm_campaign=Badge_Grade) [![DeepSource](https://static.deepsource.io/deepsource-badge-light-mini.svg)](https://deepsource.io/gh/UsergeTeam/Userge/?ref=repository-badge)
[![Build Status](https://travis-ci.com/UsergeTeam/Userge.svg?branch=dev)](https://travis-ci.com/UsergeTeam/Userge) [![DeepSource](https://static.deepsource.io/deepsource-badge-light-mini.svg)](https://deepsource.io/gh/UsergeTeam/Userge/?ref=repository-badge)

> **Userge** is a Powerful , _Pluggable_ Telegram UserBot written in _Python_ using [Pyrogram](https://github.com/pyrogram/pyrogram).
Expand Down
17 changes: 10 additions & 7 deletions genStrSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@
#
# All rights reserved.

import os
import asyncio

from pyrogram import Client
import asyncio
from dotenv import load_dotenv

if os.path.isfile("config.env"):
load_dotenv("config.env")

async def genStrSession():
async with Client(
"Userge",
api_id=int(input("enter Telegram APP ID: ")),
api_hash=input("enter Telegram API HASH: ")
) as Userge:
print(Userge.export_session_string())

"Userge",
api_id=int(os.environ.get("API_ID") or input("Enter Telegram APP ID: ")),
api_hash=os.environ.get("API_HASH") or input("Enter Telegram API HASH: ")
) as userge:
print(f"\nHere Your String -> {userge.export_session_string()}")

if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(genStrSession())
2 changes: 1 addition & 1 deletion runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-3.8.2
python-3.8.3
2 changes: 2 additions & 0 deletions userge/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class Config:

DOWN_PATH = os.environ.get("DOWN_PATH", "downloads").rstrip('/') + '/'

TMP_PATH = "userge/plugins/temp/"

SCREENSHOT_API = os.environ.get("SCREENSHOT_API", None)

CURRENCY_API = os.environ.get("CURRENCY_API", None)
Expand Down
8 changes: 3 additions & 5 deletions userge/plugins/tools/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
from userge.utils import get_import_path
from userge.plugins import ROOT

TMP_PATH = "userge/plugins/temp/"


@userge.on_cmd("status", about={
'header': "list plugins, commands, filters status",
Expand Down Expand Up @@ -350,9 +348,9 @@ async def load(message: Message):
if replied and replied.document:
file_ = replied.document
if file_.file_name.endswith('.py') and file_.file_size < 2 ** 20:
if not os.path.isdir(TMP_PATH):
os.makedirs(TMP_PATH)
t_path = os.path.join(TMP_PATH, file_.file_name)
if not os.path.isdir(Config.TMP_PATH):
os.makedirs(Config.TMP_PATH)
t_path = os.path.join(Config.TMP_PATH, file_.file_name)
if os.path.isfile(t_path):
os.remove(t_path)
await replied.download(file_name=t_path)
Expand Down
16 changes: 12 additions & 4 deletions userge/plugins/tools/restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#
# All rights reserved.


import time
import asyncio
import shutil

from userge import userge, Message, Config

Expand All @@ -17,12 +17,20 @@

@userge.on_cmd('restart', about={
'header': "Restarts the bot and reload all plugins",
'flags': {'-h': "restart heroku dyno"},
'usage': "{tr}restart\n{tr}restart -h"})
'flags': {
'-h': "restart heroku dyno",
'-t': "clean temp loaded plugins",
'-d': "clean working folder"},
'usage': "{tr}restart [flag | flags]",
'examples': "{tr}restart -t -d"}, del_pre=True)
async def restart_cmd_handler(message: Message):
await message.edit("Restarting Userge Services", log=__name__)
LOG.info("USERGE Services - Restart initiated")
if Config.HEROKU_APP and '-h' in message.flags:
if 't' in message.flags:
shutil.rmtree(Config.TMP_PATH, ignore_errors=True)
if 'd' in message.flags:
shutil.rmtree(Config.DOWN_PATH, ignore_errors=True)
if Config.HEROKU_APP and 'h' in message.flags:
await message.edit(
'`Heroku app found, trying to restart dyno...\nthis will take upto 30 sec`', del_in=3)
Config.HEROKU_APP.restart()
Expand Down
3 changes: 2 additions & 1 deletion userge/plugins/tools/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
'-master': "select master branch",
'-beta': "select beta branch",
'-alpha': "select alpha branch"},
'usage': "{tr}update or {tr}update -[branch_name] : check updates from default branch\n"
'usage': "{tr}update : check updates from default branch\n"
"{tr}update -[branch_name] : check updates from any branch\n"
"add -pull if you want to pull updates\n"
"add -push if you want to push updates to heroku",
'examples': "{tr}update -beta -pull -push"}, del_pre=True)
Expand Down
4 changes: 1 addition & 3 deletions userge/utils/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
#
# All rights reserved.

from asyncio.exceptions import CancelledError

class StopConversation(CancelledError):
class StopConversation(Exception):
"""Exception to raise if conversation terminated"""

class ProcessCanceled(Exception):
Expand Down

0 comments on commit 35afc66

Please sign in to comment.