This repository was archived by the owner on May 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# Copyright (C) 2020 BY - GitHub.com/code-rgb [TG - @deleteduser420] | ||
# All rights reserved. | ||
|
||
|
||
|
||
from userge import Config, Message, userge | ||
from git import Repo | ||
import os | ||
from userge.utils import humanbytes | ||
|
||
|
||
@userge.on_cmd( | ||
"cmdinfo", | ||
about={ | ||
"header": "find plugin and other info for a given command", | ||
"description": "you can also provide optional text to search within the plugin", | ||
"usage": "{tr}cmdinfo [cmd] | [optional text]", | ||
"examples": "{tr}cmdinfo .ars\n" | ||
"{tr}cmdinfo .ars | tracemoepy" | ||
}, | ||
) | ||
async def see_info(message: Message): | ||
cmd_str = message.input_str | ||
if not cmd_str: | ||
return await message.err('Provide a Valid Command to Search', del_in=5) | ||
word = None | ||
if '|' in cmd_str: | ||
cmd_str, word = cmd_str.split('|', 1) | ||
cmd_str = cmd_str.strip() | ||
other_trigger = ['.', Config.SUDO_TRIGGER] | ||
cmd_list = list(userge.manager.commands) | ||
found = True | ||
if not (cmd_str.startswith(Config.CMD_TRIGGER) and (cmd_str in cmd_list)): | ||
found = False | ||
for character in other_trigger: | ||
if (cmd_str.startswith(character) and (cmd_str.replace(character, Config.CMD_TRIGGER) in cmd_list)): | ||
cmd_str = cmd_str.replace(character, Config.CMD_TRIGGER) | ||
found = True | ||
break | ||
if cmd_str.isalpha() and (Config.CMD_TRIGGER + cmd_str) in cmd_list: | ||
found = True | ||
cmd_str = Config.CMD_TRIGGER + cmd_str | ||
if not found: | ||
return await message.err('provide a valid command name', del_in=5) | ||
repo = Repo() | ||
branch = repo.active_branch.name | ||
if branch == "master": | ||
branch = "alpha" | ||
unofficial_repo = 'https://github.com/code-rgb/Userge-Plugins/blob/master/plugins/' | ||
plugin_name = userge.manager.commands[cmd_str].plugin_name | ||
plugin_loc = ('/' + userge.manager.plugins[plugin_name].parent).replace('/plugins', '') | ||
if plugin_loc == '/unofficial': | ||
plugin_link = f"{unofficial_repo}/{plugin_name}.py" | ||
elif plugin_loc == '/temp': | ||
plugin_link = False | ||
else: | ||
plugin_link = "{}/blob/{}/userge/plugins{}/{}.py".format( | ||
Config.UPSTREAM_REPO, | ||
branch, | ||
plugin_loc, | ||
plugin_name | ||
) | ||
local_path = f"userge/plugins{plugin_loc}/{plugin_name}.py" | ||
f_size = humanbytes(os.stat(local_path).st_size) | ||
search_path = count_lines(local_path, word) if word else count_lines(local_path) | ||
result = f""" | ||
<b>•> CMD:</b> <code>{cmd_str}</code> | ||
📂 <b>Path : </b><code>{local_path} | ||
- Size on Disc: {f_size} | ||
- No. of lines: {search_path[0]}</code> | ||
""" | ||
if plugin_link: | ||
result += f"\n💻 <b>[View Code on Github]({plugin_link})</b>" | ||
if word: | ||
result += f"\n\n🔍 <b>Matches for:</b> {word}\n" | ||
s_result = '' | ||
if len(search_path[1]) == 0: | ||
s_result += ' ❌ Not Found !' | ||
else: | ||
line_c = 0 | ||
for line in search_path[1]: | ||
line_c += 1 | ||
s_result += f'[#L{line}]({plugin_link}#L{line}) ' | ||
if line_c > 5: | ||
break | ||
result += '<b>{}</b>'.format(s_result) | ||
await message.edit( | ||
result, | ||
disable_web_page_preview=True | ||
) | ||
|
||
|
||
def count_lines(cmd_path: str, word=None): | ||
arr = [] | ||
num_lines = 0 | ||
with open(cmd_path, 'r') as f: | ||
for line in f: | ||
num_lines += 1 | ||
if word: | ||
if word in line: | ||
arr.append(num_lines) | ||
return num_lines, arr |
d07e9da
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: