Respond to start and help commands
This commit is contained in:
parent
472d1f09d9
commit
dbf8609842
17
bot.py
17
bot.py
|
@ -9,6 +9,7 @@ import logging
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from telethon import TelegramClient, events
|
from telethon import TelegramClient, events
|
||||||
|
from telethon.tl.custom import Button
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
# Enable logging
|
# Enable logging
|
||||||
|
@ -28,6 +29,7 @@ bot = TelegramClient('xkcd', 6, 'eb06d4abfb49dc3eeb1aeb98ae0f581e')
|
||||||
bot.parse_mode = 'html'
|
bot.parse_mode = 'html'
|
||||||
|
|
||||||
session = None # set later
|
session = None # set later
|
||||||
|
me = None # set later
|
||||||
|
|
||||||
# blockquote element -> Xkcd
|
# blockquote element -> Xkcd
|
||||||
async def parse_blockquote(elem):
|
async def parse_blockquote(elem):
|
||||||
|
@ -68,15 +70,19 @@ async def get_xkcds(text):
|
||||||
@bot.on(events.NewMessage(pattern='/start$'))
|
@bot.on(events.NewMessage(pattern='/start$'))
|
||||||
async def start(event):
|
async def start(event):
|
||||||
"""Send a message when the command /start is issued."""
|
"""Send a message when the command /start is issued."""
|
||||||
# TODO
|
await event.respond(
|
||||||
await event.respond('Hi!')
|
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$'))
|
@bot.on(events.NewMessage(pattern='/help$'))
|
||||||
async def help(event):
|
async def help(event):
|
||||||
"""Send a message when the command /help is issued."""
|
"""Send a message when the command /help is issued."""
|
||||||
# TODO
|
await event.respond(
|
||||||
await event.respond('Help!')
|
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)
|
@bot.on(events.InlineQuery)
|
||||||
|
@ -102,10 +108,11 @@ async def inlinequery(event):
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
global session
|
global session, me
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
await bot.start(bot_token=environ['TOKEN'])
|
await bot.start(bot_token=environ['TOKEN'])
|
||||||
async with bot:
|
async with bot:
|
||||||
|
me = await bot.get_me()
|
||||||
await bot.run_until_disconnected()
|
await bot.run_until_disconnected()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue