Respond to start and help commands

master
Lonami Exo 2019-05-11 21:24:37 +02:00
parent 472d1f09d9
commit dbf8609842
1 changed files with 12 additions and 5 deletions

17
bot.py
View File

@ -9,6 +9,7 @@ import logging
import aiohttp
from telethon import TelegramClient, events
from telethon.tl.custom import Button
from bs4 import BeautifulSoup
# Enable logging
@ -28,6 +29,7 @@ bot = TelegramClient('xkcd', 6, 'eb06d4abfb49dc3eeb1aeb98ae0f581e')
bot.parse_mode = 'html'
session = None # set later
me = None # set later
# blockquote element -> Xkcd
async def parse_blockquote(elem):
@ -68,15 +70,19 @@ async def get_xkcds(text):
@bot.on(events.NewMessage(pattern='/start$'))
async def start(event):
"""Send a message when the command /start is issued."""
# TODO
await event.respond('Hi!')
await event.respond(
f"Hello! I'm {me.username} and I search for XKCD when used inline.",
buttons=Button.switch_inline('Try it!', 'cheaply')
)
@bot.on(events.NewMessage(pattern='/help$'))
async def help(event):
"""Send a message when the command /help is issued."""
# TODO
await event.respond('Help!')
await event.respond(
f"I only work inline, and it is my job to search for XKCD comics!",
buttons=Button.switch_inline('Try it!', 'cheaply')
)
@bot.on(events.InlineQuery)
@ -102,10 +108,11 @@ async def inlinequery(event):
async def main():
global session
global session, me
async with aiohttp.ClientSession() as session:
await bot.start(bot_token=environ['TOKEN'])
async with bot:
me = await bot.get_me()
await bot.run_until_disconnected()