2
0
mirror of https://github.com/Nick80835/microbot synced 2025-09-05 08:55:51 +00:00
Files
microbot/ubot/modules/howdoi.py
2023-10-16 09:54:01 -04:00

24 lines
610 B
Python

# SPDX-License-Identifier: GPL-2.0-or-later
import os
import re
from howdoi import howdoi
from ubot.micro_bot import micro_bot
ldr = micro_bot.loader
os.environ["HOWDOI_SEARCH_ENGINE"] = "bing"
@ldr.add("hdi")
async def howdoi_cmd(event):
if not event.args:
await event.reply(f"`Syntax: {ldr.settings.get_config('cmd_prefix') or '.'}hdi <question>`")
return
response = howdoi.howdoi(vars(howdoi.get_parser().parse_args(event.args.split(' '))))
response = re.sub(r'\n\n+', '\n\n', response).strip()
await event.reply(f"**Query:**\n{event.args}\n**Answer:**\n{response}")