From dbf86098420170b47825a94dc788e2b4613e1948 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sat, 11 May 2019 21:24:37 +0200 Subject: [PATCH] Respond to start and help commands --- bot.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bot.py b/bot.py index 68aeb6f..b260f34 100644 --- a/bot.py +++ b/bot.py @@ -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()