Skip to content

Commit

Permalink
add syntax highlighting (UsergeTeam#532)
Browse files Browse the repository at this point in the history
* add syntax highlighting

* fix f-string error

* typo
  • Loading branch information
subinps authored Oct 17, 2022
1 parent b888849 commit 4e77aae
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
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
2 changes: 1 addition & 1 deletion userge/core/methods/decorators/raw_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,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
6 changes: 3 additions & 3 deletions userge/plugins/builtin/executor/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,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 +246,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
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
2 changes: 1 addition & 1 deletion userge/utils/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,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

0 comments on commit 4e77aae

Please sign in to comment.