2
0
mirror of https://github.com/Nick80835/microbot synced 2025-09-05 17:05:52 +00:00
Files
microbot/ubot/modules/howdoi.py

24 lines
610 B
Python
Raw Normal View History

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