Skip to content

Commit

Permalink
Merge branch 'UsergeTeam:alpha' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
hrithikvish authored May 18, 2023
2 parents 4699ce1 + 3d883ec commit dbc06f0
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 43 deletions.
2 changes: 1 addition & 1 deletion min_loader.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.6
5.0
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dnspython
heroku3
motor
pyrogram>=2.0.30
pyrogram==2.0.58
tgcrypto
4 changes: 2 additions & 2 deletions userge/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,11 @@ def _get_log_client(self) -> _AbstractUserge:

async def _log_success(self) -> None:
# pylint: disable=protected-access
await self._get_log_client()._channel.log("```Userge started successfully```")
await self._get_log_client()._channel.log("<pre>Userge started successfully</pre>")

async def _log_exit(self) -> None:
# pylint: disable=protected-access
await self._get_log_client()._channel.log("```Exiting Userge ...```")
await self._get_log_client()._channel.log("<pre>\nExiting Userge ...</pre>")

def begin(self, coro: Optional[Awaitable[Any]] = None) -> None:
""" start userge """
Expand Down
3 changes: 2 additions & 1 deletion userge/core/methods/decorators/raw_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ async def _raise_func(r_c: Union['_client.Userge', '_client.UsergeBot'],
if r_m.chat.type in (enums.ChatType.PRIVATE, enums.ChatType.BOT):
await r_m.reply(f"< **ERROR**: {text} ! >")
else:
# skipcq: PYL-W0212
await r_c._channel.log(f"{text}\nCaused By: [link]({r_m.link})", "ERROR")


Expand Down Expand Up @@ -347,7 +348,7 @@ async def template(r_c: Union['_client.Userge', '_client.UsergeBot'],
await self._channel.log(f"**PLUGIN** : `{module}`\n"
f"**FUNCTION** : `{func.__name__}`\n"
f"**ERROR** : `{f_e or None}`\n"
f"\n```{format_exc().strip()}```",
f"```python\n{format_exc().strip()}```",
"TRACEBACK")
finally:
if flt.propagate:
Expand Down
4 changes: 2 additions & 2 deletions userge/core/types/new/channel_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def get_link(message_id: int) -> str:
Returns:
str
"""
return "<b><a href='https://t.me/c/{}/{}'>Preview</a></b>".format(
str(config.LOG_CHANNEL_ID)[4:], message_id)
link = f"https://t.me/c/{str(config.LOG_CHANNEL_ID)[4:]}/{message_id}"
return f"<b><a href='{link}'>Preview</a></b>"

async def log(self, text: str, name: str = '') -> int:
"""\nsend text message to log channel.
Expand Down
2 changes: 1 addition & 1 deletion userge/core/types/new/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def get_response(self, *, timeout: Union[int, float] = 0,
filter specific response.
Returns:
On success, the recieved Message is returned.
On success, the received Message is returned.
"""
if self._count >= self._limit:
raise _MsgLimitReached
Expand Down
10 changes: 7 additions & 3 deletions userge/plugins/builtin/executor/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from contextlib import contextmanager
from enum import Enum
from getpass import getuser
from shutil import which
from typing import Awaitable, Any, Callable, Dict, Optional, Tuple, Iterable

import aiofiles
Expand All @@ -30,6 +31,7 @@
except ImportError:
# pylint: disable=ungrouped-imports
from os import kill as killpg
# pylint: disable=ungrouped-imports
from signal import CTRL_C_EVENT as SIGKILL

def geteuid() -> int:
Expand Down Expand Up @@ -197,13 +199,13 @@ async def eval_(message: Message):
async def _callback(output: Optional[str], errored: bool):
final = ""
if not silent_mode:
final += f"**>** {replied.link if is_file else f'```{cmd}```'}\n\n"
final += "**>**" + (replied.link if is_file else f"```python\n{cmd}```") + "\n\n"
if isinstance(output, str):
output = output.strip()
if output == '':
output = None
if output is not None:
final += f"**>>** ```{output}```"
final += f"**>>** ```python\n{output}```"
if errored and message.chat.type in (
enums.ChatType.GROUP,
enums.ChatType.SUPERGROUP,
Expand Down Expand Up @@ -246,7 +248,7 @@ async def _callback(output: Optional[str], errored: bool):
await future
except asyncio.CancelledError:
await asyncio.gather(msg.canceled(),
CHANNEL.log(f"**EVAL Process Canceled!**\n\n```{cmd}```"))
CHANNEL.log(f"**EVAL Process Canceled!**\n\n```python\n{cmd}```"))
finally:
_EVAL_TASKS.pop(future, None)

Expand Down Expand Up @@ -463,6 +465,8 @@ async def execute(cls, cmd: str) -> 'Term':
stderr=asyncio.subprocess.PIPE)
if setsid:
kwargs['preexec_fn'] = setsid
if sh := which(os.environ.get("USERGE_SHELL", "bash")):
kwargs['executable'] = sh
process = await asyncio.create_subprocess_shell(cmd, **kwargs)
t_obj = cls(process)
t_obj._start()
Expand Down
40 changes: 20 additions & 20 deletions userge/plugins/builtin/loader/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def core(message: Message):
set_branch, branch = 'b' in flags, flags.get('b')
set_version, version = 'v' in flags, int(flags.get('v') or 0)

await message.edit("```processing ...```")
await message.edit("<pre>processing ...</pre>")

if fetch:
await api.fetch_core()
Expand Down Expand Up @@ -97,10 +97,10 @@ async def core(message: Message):
await message.edit(
f"done, do `{config.CMD_TRIGGER}restart -h` to apply changes", del_in=3)
else:
await message.edit("```didn't change anything```", del_in=3)
await message.edit("<pre>didn't change anything</pre>", del_in=3)

elif fetch:
await message.edit("```fetched core repo```", del_in=3)
await message.edit("<pre>fetched core repo</pre>", del_in=3)

else:
core_repo = await api.get_core()
Expand Down Expand Up @@ -152,12 +152,12 @@ async def repos(message: Message):
set_version, version = 'v' in flags, int(flags.get('v') or 0)
set_priority, priority = 'p' in flags, flags.get('p')

await message.edit("```processing ...```")
await message.edit("<pre>processing ...</pre>")

if repo_id <= 0:
if fetch:
await api.fetch_repos()
await message.edit("```fetched plugins repos```", del_in=3)
await message.edit("<pre>fetched plugins repos</pre>", del_in=3)

elif invalidate:
await api.invalidate_repos_cache()
Expand All @@ -169,7 +169,7 @@ async def repos(message: Message):
plg_repos = await api.get_repos()

if not plg_repos:
await message.edit("```no repos found```", del_in=3)
await message.edit("<pre>no repos found</pre>", del_in=3)
return

out = "**Repos Details**\n\n"
Expand Down Expand Up @@ -251,10 +251,10 @@ async def repos(message: Message):
await message.edit(
f"done, do `{config.CMD_TRIGGER}restart -h` to apply changes", del_in=3)
else:
await message.edit("```didn't change anything```", del_in=3)
await message.edit("<pre>didn't change anything</pre>", del_in=3)

elif fetch:
await message.edit(f"```fetched plugins repo: {repo_id}```", del_in=3)
await message.edit(f"<pre>fetched plugins repo: {repo_id}</pre>", del_in=3)

else:
await message.err("invalid flags")
Expand Down Expand Up @@ -284,14 +284,14 @@ async def add_repo(message: Message):
await message.err("no input url")
return

await message.edit("```processing ...```")
await message.edit("<pre>processing ...</pre>")

if await api.add_repo(priority, branch, url):
await message.edit("added repo, "
f"do `{config.CMD_TRIGGER}restart -h` to apply changes", del_in=3)

else:
await message.edit("```repo was already added or invalid```", del_in=3)
await message.edit("<pre>repo was already added or invalid</pre>", del_in=3)


@userge.on_cmd("rmrepo", about={
Expand All @@ -307,14 +307,14 @@ async def rm_repo(message: Message):
await message.err("empty or invalid repo id")
return

await message.edit("```processing ...```")
await message.edit("<pre>processing ...</pre>")

if await api.remove_repo(int(repo_id)):
await message.edit("removed repo, "
f"do `{config.CMD_TRIGGER}restart -h` to apply changes", del_in=3)

else:
await message.edit("```couldn't find that repo```", del_in=3)
await message.edit("<pre>couldn't find that repo</pre>", del_in=3)


@userge.on_cmd("consts", about={
Expand All @@ -325,7 +325,7 @@ async def consts(message: Message):
data_ = await api.get_constraints()

if not data_:
await message.edit("```no constraints found```", del_in=3)
await message.edit("<pre>no constraints found</pre>", del_in=3)
return

out = ""
Expand Down Expand Up @@ -363,14 +363,14 @@ async def add_consts(message: Message):
await message.err("no data provided")
return

await message.edit("```processing ...```")
await message.edit("<pre>processing ...</pre>")

if await api.add_constraints(c_type, data.split()):
await message.edit("added constraints, "
f"do `{config.CMD_TRIGGER}restart -h` to apply changes", del_in=3)

else:
await message.edit("```didn't add anything```", del_in=3)
await message.edit("<pre>didn't add anything</pre>", del_in=3)


@userge.on_cmd("rmconsts", about={
Expand Down Expand Up @@ -400,14 +400,14 @@ async def rm_consts(message: Message):
await message.err("no data provided")
return

await message.edit("```processing ...```")
await message.edit("<pre>processing ...</pre>")

if await api.remove_constraints(c_type, data.split()):
await message.edit("removed constraints, "
f"do `{config.CMD_TRIGGER}restart -h` to apply changes", del_in=3)

else:
await message.edit("```didn't remove anything```", del_in=3)
await message.edit("<pre>didn't remove anything</pre>", del_in=3)


@userge.on_cmd("clrconsts", about={
Expand All @@ -429,14 +429,14 @@ async def clr_consts(message: Message):
await message.err("invalid type")
return

await message.edit("```processing ...```")
await message.edit("<pre>processing ...</pre>")

if await api.clear_constraints(c_type):
await message.edit("cleared constraints, "
f"do `{config.CMD_TRIGGER}restart -h` to apply changes", del_in=3)

else:
await message.edit("```nothing found to clear```", del_in=3)
await message.edit("<pre>nothing found to clear</pre>", del_in=3)


@userge.on_cmd("update", about={
Expand Down Expand Up @@ -536,7 +536,7 @@ async def update(message: Message):
else:
await message.edit_or_send_as_file(updates, del_in=0, disable_web_page_preview=True)
else:
await message.edit("```no updates found```", del_in=3)
await message.edit("<pre>no updates found</pre>", del_in=3)


def _updates_to_str(updates: List[Update]) -> str:
Expand Down
29 changes: 21 additions & 8 deletions userge/plugins/builtin/sudo/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ async def add_sudo_cmd(message: Message):
@userge.on_cmd("delscmd", about={
'header': "delete sudo commands",
'flags': {'-all': "remove all sudo commands"},
'usage': "{tr}delscmd [command name]\n{tr}delscmd -all"}, allow_channels=False)
'usage': "{tr}delscmd [command names separated by space]\n{tr}delscmd -all"},
allow_channels=False)
async def del_sudo_cmd(message: Message):
""" delete sudo cmd """
if '-all' in message.flags:
Expand All @@ -170,13 +171,25 @@ async def del_sudo_cmd(message: Message):
if not cmd:
await message.err('input not found!')
return
if cmd not in sudo.COMMANDS:
await message.edit(f"cmd : `{cmd}` not in **SUDO**!", del_in=5)
else:
sudo.COMMANDS.remove(cmd)
await asyncio.gather(
SUDO_CMDS_COLLECTION.delete_one({'_id': cmd}),
message.edit(f"cmd : `{cmd}` removed from **SUDO**!", del_in=5, log=__name__))
NOT_IN_SUDO = []
IS_REMOVED = []
for ncmd in cmd.split(" "):
if ncmd not in sudo.COMMANDS:
NOT_IN_SUDO.append(ncmd)
else:
sudo.COMMANDS.remove(ncmd)
IS_REMOVED.append(ncmd)
if IS_REMOVED:
await SUDO_CMDS_COLLECTION.delete_many({'_id': {'$in': IS_REMOVED}})
await message.edit(
f"cmds : `{' '.join(IS_REMOVED)}` removed from **SUDO**!",
del_in=5, log=__name__)
if NOT_IN_SUDO and not IS_REMOVED:
await message.edit(
f"cmds : `{' '.join(NOT_IN_SUDO)}` not in **SUDO**!", del_in=5)
elif NOT_IN_SUDO:
await message.reply_text(
f"cmds : `{' '.join(NOT_IN_SUDO)}` not in **SUDO**!", del_in=5)


@userge.on_cmd("vscmd", about={'header': "view sudo cmds"}, allow_channels=False)
Expand Down
7 changes: 4 additions & 3 deletions userge/utils/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import time
from math import floor
from typing import Dict, Tuple
from typing import Dict, Tuple, Optional

from pyrogram.errors.exceptions import FloodWait

Expand All @@ -26,10 +26,11 @@ async def progress(current: int,
message: 'userge.Message',
ud_type: str,
file_name: str = '',
delay: int = config.Dynamic.EDIT_SLEEP_TIMEOUT) -> None:
delay: Optional[int] = None) -> None:
""" progress function """
if message.process_is_canceled:
await message.client.stop_transmission()
delay = delay or config.Dynamic.EDIT_SLEEP_TIMEOUT
task_id = f"{message.chat.id}.{message.id}"
if current == total:
if task_id not in _TASKS:
Expand All @@ -52,7 +53,7 @@ async def progress(current: int,
time_to_completion = time_formatter(int((total - current) / speed))
progress_str = \
"__{}__ : `{}`\n" + \
"```[{}{}]```\n" + \
"```\n[{}{}]```\n" + \
"**Progress** : `{}%`\n" + \
"**Completed** : `{}`\n" + \
"**Total** : `{}`\n" + \
Expand Down
2 changes: 1 addition & 1 deletion userge/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

__major__ = 1
__minor__ = 0
__micro__ = 1
__micro__ = 2

__python_version__ = f"{version_info[0]}.{version_info[1]}.{version_info[2]}"
__license__ = "[GNU GPL v3.0](https://github.com/UsergeTeam/Userge/blob/master/LICENSE)"
Expand Down

0 comments on commit dbc06f0

Please sign in to comment.