-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.py
47 lines (37 loc) · 1.69 KB
/
bot.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import hashlib
import logging
import random
from aiogram import Bot, Dispatcher, executor
from aiogram.types import InlineQuery, \
InputTextMessageContent, InlineQueryResultArticle, Message
API_TOKEN = '123:123' # your telegram bot token
logging.basicConfig(level=logging.DEBUG)
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)
@dp.inline_handler()
async def inline_echo(inline_query: InlineQuery):
phrases = ['yes.', 'no.', 'hohoho', 'aaagh']
choice = random.choice(phrases)
text = inline_query.query + '*\n{}*'.format(choice)
input_content = InputTextMessageContent(text, parse_mode='markdown')
result_id: str = hashlib.md5(text.encode()).hexdigest()
thumb = 'https://memepedia.ru/wp-content/uploads/2022/02/hohoho-nou-mem-govorjashchij-ben-768x512.jpg'
item = InlineQueryResultArticle(
id=result_id,
title=inline_query.query or "Ben's answer",
description=choice,
input_message_content=input_content,
thumb_url=thumb
)
await inline_query.answer([item], is_personal=True)
@dp.message_handler()
async def any_message_handler(message: Message):
botname = await bot.get_me()
await message.answer(
"This bot can help you find out the answers to your questions.\n"
"It works automatically, you don't need to add it anywhere.\n"
f"Simply open any of your chats and type @{botname['username']} + something in the message field. Then tap on a result to send..\n\n"
f"For example, try <code>@{botname['username']} telegram is good?</code>\n"
"My repo on github - https://github.com/l1v0n1/ben-talking-bot", parse_mode='HTML')
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)