Skip to content

Commit

Permalink
optimizing userge
Browse files Browse the repository at this point in the history
  • Loading branch information
rking32 committed Apr 23, 2020
1 parent 5d14e45 commit 487cd1f
Show file tree
Hide file tree
Showing 54 changed files with 839 additions and 1,155 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ async def testing(message: Message):

> TODO: add Docker Support.
### Video Tutorial 🎥

[![Tutorial](resources/tutorial.jpg)](https://youtu.be/-XJj686zeiY)

### Support & Discussions 👥

> Head over to the [Discussion Group](https://t.me/slbotsbugs) and [Update Channel](https://t.me/theUserge)
Expand Down
5 changes: 4 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"name": "Userge",
"description": "telegram pluggable userbot",
"logo": "https://imgur.com/download/Inyeb1S",
"keywords": [
"userge",
"telegram",
"pluggable",
"userbot"
],
"repository": "https://github.com/uaudith/Userge",
"repository": "https://github.com/UsergeTeam/Userge",
"website": "https://github.com/Userge",
"success_url": "https://t.me/theUserge",
"env": {
"APP_ID": {
"description": "Get this value from https://my.telegram.org"
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ selenium
setuptools>=40.3.0
speedtest-cli
tgcrypto
urbandict
urbandict==0.5
wget
wikipedia
Binary file added resources/tutorial.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion userge/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class Config:

HEROKU_GIT_URL = None

PUSHING = False

MSG_DELETE_TIMEOUT = 120

WELCOME_DELETE_TIMEOUT = 120
Expand Down Expand Up @@ -136,7 +138,7 @@ class Config:
LOG.info("Downloading BINs...")

for binary, path in BINS.items():
LOG.debug(f"Downloading {binary}...")
LOG.debug("Downloading %s...", binary)
downloader = SmartDL(binary, path, progress_bar=False)
downloader.start()
os.chmod(path, 0o755)
108 changes: 101 additions & 7 deletions userge/core/_userge/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,23 +196,34 @@ async def send_message(self,

def on_cmd(self,
command: str,
about: str,
about: Union[str, Dict[str, str]],
group: int = 0,
name: str = '',
trigger: str = '.',
filter_me: bool = True,
**kwargs: Union[str, bool]) -> Callable[[PYROFUNC], PYROFUNC]:
**kwargs: Union[str, bool, Dict[str, str]]) -> Callable[[PYROFUNC], PYROFUNC]:
"""
Decorator for handling messages.
\nDecorator for handling messages.
Example:
@userge.on_cmd('test', about='for testing')
Parameters:
command (``str``):
command name to execute (without trigger!).
about (``str``):
help string for command.
about (``str`` | ``dict``):
help string or dict for command.
{
'header': ``str``,
'description': ``str``,
'flags': ``str`` | ``dict``,
'options': ``str`` | ``dict``,
'types': ``str`` | ``list``,
'usage': ``str``,
'examples': ``str`` | ``list``,
'others': ``str``,
'any_title': ``str`` | ``list`` | ``dict``
}
group (``int``, *optional*):
The group identifier, defaults to 0.
name (``str``, *optional*):
Expand Down Expand Up @@ -331,13 +342,93 @@ def get_help(self,
def __add_help(self,
module: str,
cname: str = '',
chelp: str = '',
chelp: Union[str, Dict[str, str]] = '',
**_: Union[str, bool]) -> None:
if cname:
LOG.debug(LOG_STR, f"Updating Help Dict => [ {cname} : {chelp} ]")

mname = module.split('.')[-1]

if isinstance(chelp, dict):
tmp_chelp = ''

if 'header' in chelp:
tmp_chelp += f"__**{chelp['header'].title()}**__"
del chelp['header']

if 'description' in chelp:
tmp_chelp += ("\n\n📝 --**Description**-- :\n\n "
f"__{chelp['description'].capitalize()}__")
del chelp['description']

if 'flags' in chelp:
tmp_chelp += f"\n\n⛓ --**Available Flags**-- :\n"

if isinstance(chelp['flags'], dict):
for f_n, f_d in chelp['flags'].items():
tmp_chelp += f"\n ▫ `{f_n}` : __{f_d.lower()}__"
else:
tmp_chelp += f"\n {chelp['flags']}"
del chelp['flags']

if 'options' in chelp:
tmp_chelp += f"\n\n🕶 --**Available Options**-- :\n"

if isinstance(chelp['options'], dict):
for o_n, o_d in chelp['options'].items():
tmp_chelp += f"\n ▫ `{o_n}` : __{o_d.lower()}__"
else:
tmp_chelp += f"\n {chelp['options']}"
del chelp['options']

if 'types' in chelp:
tmp_chelp += f"\n\n🎨 --**Supported Types**-- :\n\n"

if isinstance(chelp['types'], list):
for _opt in chelp['types']:
tmp_chelp += f" `{_opt}` ,"
else:
tmp_chelp += f" {chelp['types']}"
del chelp['types']

if 'usage' in chelp:
tmp_chelp += f"\n\n✒ --**Usage**-- :\n\n`{chelp['usage']}`"
del chelp['usage']

if 'examples' in chelp:
tmp_chelp += f"\n\n✏ --**Examples**-- :\n"

if isinstance(chelp['examples'], list):
for ex_ in chelp['examples']:
tmp_chelp += f"\n `{ex_}`\n"
else:
tmp_chelp += f"\n `{chelp['examples']}`"
del chelp['examples']

if 'others' in chelp:
tmp_chelp += f"\n\n📎 --**Others**-- :\n\n{chelp['others']}"
del chelp['others']

if chelp:
for t_n, t_d in chelp.items():
tmp_chelp += f"\n\n⚙ --**{t_n.title()}**-- :\n"

if isinstance(t_d, dict):
for o_n, o_d in t_d.items():
tmp_chelp += f"\n ▫ `{o_n}` : __{o_d.lower()}__"

elif isinstance(t_d, list):
tmp_chelp += '\n'
for _opt in t_d:
tmp_chelp += f" `{_opt}` ,"

else:
tmp_chelp += '\n'
tmp_chelp += t_d

chelp = tmp_chelp
del tmp_chelp

if mname in self.__help_dict:
self.__help_dict[mname].update({cname: chelp})

Expand All @@ -348,7 +439,8 @@ def __build_decorator(self,
log: str,
filters: Filters,
group: int,
**kwargs: Union[str, bool]) -> Callable[[PYROFUNC], PYROFUNC]:
**kwargs: Union[
str, bool, Dict[str, str]]) -> Callable[[PYROFUNC], PYROFUNC]:

def __decorator(func: PYROFUNC) -> PYROFUNC:

Expand Down Expand Up @@ -441,6 +533,8 @@ async def restart(self) -> None:

os.execl(sys.executable, sys.executable, '-m', 'userge')

sys.exit()

def begin(self) -> None:
"""
This will start the Userge.
Expand Down
21 changes: 5 additions & 16 deletions userge/core/_userge/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,12 @@ def __msg_to_dict(message: RawMessage) -> Dict[str, object]:
if '_client' in kwargs_:
del kwargs_['_client']

if '_Message__channel' in kwargs_:
del kwargs_['_Message__channel']
for key_ in ['channel', 'filtered', 'process_canceled',
'filtered_input_str', 'flags', 'kwargs']:
tmp_ = '_Message__' + key_

if '_Message__filtered' in kwargs_:
del kwargs_['_Message__filtered']

if '_Message__process_canceled' in kwargs_:
del kwargs_['_Message__process_canceled']

if '_Message__filtered_input_str' in kwargs_:
del kwargs_['_Message__filtered_input_str']

if '_Message__flags' in kwargs_:
del kwargs_['_Message__flags']

if '_Message__kwargs' in kwargs_:
del kwargs_['_Message__kwargs']
if tmp_ in kwargs_:
del kwargs_[tmp_]

return kwargs_

Expand Down
Loading

0 comments on commit 487cd1f

Please sign in to comment.