-
Notifications
You must be signed in to change notification settings - Fork 29
/
faq.py
29 lines (24 loc) · 1.01 KB
/
faq.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import json
import re
import os
from telethon import events
# TODO Make this better
template = "The cause of this error is most likely {cause}. To fix it you need to {solution}"
with open(os.path.join(os.path.dirname(__file__), "faq.json"), "r", encoding="utf-8") as file:
errors = json.load(file)
FAQ_URL = 'https://docs.telethon.dev/en/stable/quick-references/faq.html'
async def init(bot):
@bot.on(events.NewMessage)
async def handler(event):
for error in errors:
if re.search(error["pattern"], event.raw_text, flags=re.IGNORECASE):
await event.reply(template.format(cause=error["cause"], solution=error["solution"]))
break
@bot.on(events.NewMessage(pattern='#faq'))
async def handler(event):
"""#faq: Tell the user that their problem is in the faq."""
await event.delete()
await event.respond(
f"You can find a solution to your problem in [Telethon's FAQ]({FAQ_URL})",
reply_to=event.reply_to_msg_id
)