drop cmdinfo, help, repo, cancel from ub plugins(added to core)

This commit is contained in:
thedragonsinn
2024-03-14 18:42:42 +05:30
parent ddd7aab668
commit c806bde18b
5 changed files with 0 additions and 116 deletions

View File

@@ -1,39 +0,0 @@
import os
from app import BOT, Config, Message, bot
@bot.add_cmd(cmd="ci")
async def cmd_info(bot: BOT, message: Message):
"""
CMD: CI (CMD INFO)
INFO: Get Github File URL of a Command.
USAGE: .ci ci
"""
cmd = message.filtered_input
if not cmd or cmd not in Config.CMD_DICT.keys():
await message.reply("Give a valid cmd.", del_in=5)
return
cmd_path = Config.CMD_DICT[cmd].cmd_path
plugin_path = os.path.relpath(cmd_path, os.curdir)
repo = Config.REPO.remotes.origin.url
branch = Config.REPO.active_branch
remote_url = os.path.join(str(repo), "blob", str(branch), plugin_path)
resp_str = (
f"<pre language=css>Command: {cmd}"
f"\nPath: {cmd_path}</pre>"
f"\nLink: <a href='{remote_url}'>Github</a>"
)
await message.reply(resp_str, disable_web_page_preview=True)
@bot.add_cmd(cmd="s")
async def search(bot: BOT, message: Message):
search_str = message.input
if not search_str:
await message.reply("Give some input to search commands.")
return
cmds = [cmd for cmd in Config.CMD_DICT.keys() if search_str in cmd]
await message.reply(f"<pre language=json>{cmds}</pre>")

View File

@@ -1,38 +0,0 @@
from collections import defaultdict
from app import BOT, Config, Message, bot
@bot.add_cmd(cmd="help")
async def cmd_list(bot: BOT, message: Message) -> None:
"""
CMD: HELP
INFO: Check info/about available cmds.
USAGE:
.help help | .help
"""
cmd = message.input.strip()
if not cmd:
await message.reply(text=get_cmds(), del_in=30, block=True)
elif cmd not in Config.CMD_DICT.keys():
await message.reply(
text=f"Invalid <b>{cmd}</b>, check {message.trigger}help", del_in=5
)
else:
raw_help_str = Config.CMD_DICT[cmd].doc
parsed_str = "\n".join(
[x.replace(" ", "", 1) for x in raw_help_str.splitlines()]
)
await message.reply(text=f"<pre language=java>{parsed_str}</pre>", del_in=30)
def get_cmds() -> str:
dir_dict = defaultdict(list)
for cmd in Config.CMD_DICT.values():
dir_dict[cmd.dirname].append(cmd.cmd)
sorted_keys = sorted(dir_dict.keys())
help_str = ""
for key in sorted_keys:
help_str += f"\n\n\n<b>{key.capitalize()}:</b>\n"
help_str += f"<pre language=json>{dir_dict[key]}</pre>"
return help_str

View File

@@ -1,11 +0,0 @@
from app import BOT, Config, Message, bot
@bot.add_cmd(cmd="repo")
async def sauce(bot: BOT, message: Message) -> None:
await bot.send_message(
chat_id=message.chat.id,
text=f"<a href='{Config.UPSTREAM_REPO}'>{Config.BOT_NAME}</a>",
reply_to_message_id=message.reply_id or message.id,
disable_web_page_preview=True,
)

View File

@@ -1,28 +0,0 @@
import asyncio
from app import BOT, Message, bot
@bot.add_cmd(cmd="c")
async def cancel_task(bot: BOT, message: Message) -> Message | None:
"""
CMD: CANCEL
INFO: Cancel a running command by replying to a message.
USAGE: .c
"""
task_id: str | None = message.replied_task_id
if not task_id:
return await message.reply(
text="Reply To a Command or Bot's Response Message.", del_in=8
)
all_tasks: set[asyncio.all_tasks] = asyncio.all_tasks()
tasks: list[asyncio.Task] | None = [x for x in all_tasks if x.get_name() == task_id]
if not tasks:
return await message.reply(
text="Task not in Currently Running Tasks.", del_in=8
)
response: str = ""
for task in tasks:
status: bool = task.cancel()
response += f"Task: __{task.get_name()}__\nCancelled: __{status}__\n"
await message.reply(response, del_in=5)