🐛 Fix help_raw command

This commit is contained in:
Lei Shi 2023-11-23 04:34:33 +01:00 committed by GitHub
parent d5165ff4e6
commit 6189542389
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 12 deletions

1
.gitignore vendored
View File

@ -26,6 +26,7 @@ share/python-wheels/
.installed.cfg .installed.cfg
*.egg *.egg
MANIFEST MANIFEST
poetry.lock
# PyInstaller # PyInstaller
# Usually these files are written by a python script from a template # Usually these files are written by a python script from a template

View File

@ -20,19 +20,31 @@ class HelpRawPlugin(Plugin):
file_path = os.path.join(os.getcwd(), "resources", "bot", "help", "help.jinja2") file_path = os.path.join(os.getcwd(), "resources", "bot", "help", "help.jinja2")
async with aiofiles.open(file_path, mode="r", encoding="utf-8") as f: async with aiofiles.open(file_path, mode="r", encoding="utf-8") as f:
html_content = await f.read() html_content = await f.read()
soup = BeautifulSoup(html_content, "lxml") soup = BeautifulSoup(html_content, "html.parser")
command_div = soup.find_all("div", _class="command") commands = []
command_div = soup.find_all("div", class_="command")
for div in command_div: for div in command_div:
command_name_div = div.find("div", _class="command_name") command_name_div = div.find("div", class_="command-name")
if command_name_div: command_description_div = div.find("div", class_="command-description")
command_description_div = div.find("div", _class="command-description") if command_name_div and command_description_div:
if command_description_div: command_name_div_text = command_name_div.text.strip()
self.help_raw += f"/{command_name_div.text} - {command_description_div}" if command_name_div_text.startswith(r"@{{bot_username}}"):
command_name_div_text = command_name_div_text.replace(
r"@{{bot_username}}", self.application.telegram.bot.name
)
commands.append(f"{command_name_div_text} - {command_description_div.text.strip()}")
if commands:
self.help_raw = "\n".join(commands)
@handler.command(command="help_raw", block=False) @handler.command(command="help_raw", block=False)
async def start(self, update: Update, _: CallbackContext): async def start(self, update: Update, _: CallbackContext):
if self.help_raw is not None: message = update.effective_message
message = update.effective_message user = update.effective_user
user = update.effective_user logger.info("用户 %s[%s] 发出 help_raw 命令", user.full_name, user.id)
logger.info("用户 %s[%s] 发出 help_raw 命令", user.full_name, user.id)
await message.reply_text(self.help_raw, allow_sending_without_reply=True) if self.help_raw is None:
await self.initialize()
if self.help_raw is None:
await message.reply_text("出错了呜呜呜~派蒙没有找到任何帮助信息")
return
await message.reply_text(self.help_raw, allow_sending_without_reply=True)