async def test_equals_list(self, test_filter_list, test_text, ignore_case): test_filter = Text(equals=test_filter_list, ignore_case=ignore_case) async def check(obj): result = await test_filter.check(obj) if ignore_case: _test_filter_list = list(map(str.lower, test_filter_list)) _test_text = test_text.lower() else: _test_filter_list = test_filter_list _test_text = test_text assert result is (_test_text in _test_filter_list) await check(Message(text=test_text)) await check(CallbackQuery(data=test_text)) await check(InlineQuery(query=test_text)) await check(Poll(question=test_text))
async def test_startswith(self, test_prefix, test_text, ignore_case): test_filter = Text(startswith=test_prefix, ignore_case=ignore_case) async def check(obj): result = await test_filter.check(obj) if ignore_case: _test_prefix = test_prefix.lower() _test_text = test_text.lower() else: _test_prefix = test_prefix _test_text = test_text return result is _test_text.startswith(_test_prefix) assert await check(Message(text=test_text)) assert await check(CallbackQuery(data=test_text)) assert await check(InlineQuery(query=test_text)) assert await check(Poll(question=test_text))
async def test_equals_string(self, test_filter_text, test_text, ignore_case): test_filter = Text(equals=test_filter_text, ignore_case=ignore_case) async def check(obj): result = await test_filter.check(obj) if ignore_case: _test_filter_text = test_filter_text.lower() _test_text = test_text.lower() else: _test_filter_text = test_filter_text _test_text = test_text return result is (_test_text == _test_filter_text) assert await check(Message(text=test_text)) assert await check(CallbackQuery(data=test_text)) assert await check(InlineQuery(query=test_text)) assert await check(Poll(question=test_text))
async def test_endswith_list(self, test_postfix_list, test_text, ignore_case): test_filter = Text(endswith=test_postfix_list, ignore_case=ignore_case) async def check(obj): result = await test_filter.check(obj) if ignore_case: _test_postfix_list = map(str.lower, test_postfix_list) _test_text = test_text.lower() else: _test_postfix_list = test_postfix_list _test_text = test_text return result is any(map(_test_text.endswith, _test_postfix_list)) assert await check(Message(text=test_text)) assert await check(CallbackQuery(data=test_text)) assert await check(InlineQuery(query=test_text)) assert await check(Poll(question=test_text))
async def test_contains_list(self, test_filter_list, test_text, ignore_case): test_filter = Text(contains=test_filter_list, ignore_case=ignore_case) async def check(obj): result = await test_filter.check(obj) if ignore_case: _test_filter_list = list(map(str.lower, test_filter_list)) _test_text = test_text.lower() else: _test_filter_list = test_filter_list _test_text = test_text return result is all( map(_test_text.__contains__, _test_filter_list)) assert await check(Message(text=test_text)) assert await check(CallbackQuery(data=test_text)) assert await check(InlineQuery(query=test_text)) assert await check(Poll(question=test_text))
async def _run_check(check, test_text): assert await check(Message(text=test_text)) assert await check(CallbackQuery(data=test_text)) assert await check(InlineQuery(query=test_text)) assert await check(Poll(question=test_text))
from os import listdir from random import choice #?????????????????????? import logging from config import TOKEN from aiogram import Bot, Dispatcher, executor, types from aiogram.types import ReplyKeyboardRemove, ReplyKeyboardMarkup, KeyboardButton, InlineKeyboardMarkup, InlineKeyboardMarkup, InlineQuery logging.basicConfig(level=logging.INFO) bot = Bot(token=TOKEN) dp = Dispatcher(bot) btn_hi = KeyboardButton('Я кнопка bth_hi') btn_end = KeyboardButton('Я кнопка btn_end') btn_atr = ReplyKeyboardMarkup() btn_atr.add(btn_hi).add(btn_end) InlineQuery('/start') @dp.message_handler(commands=['start'], commands_prefix='#') async def send_welcome_start(message: types.Message): """ This handler will be called when user sends `#start` or `/help` command """ await message.reply("Привет, этот бот скоро порвёт твоё очко.") @dp.message_handler(commands=['help'], commands_prefix='#') async def send_help(message: types.Message): """ This handler will be called when user sends `#start` or `/help` command """
async def on_process_inline_query(self, inline_query: types.InlineQuery, data: dict): inline_query.db = self.db