rate=2, ) async def cmd_version(message: types.Message) -> None: await message.reply("My Engine\n{api_info}".format( api_info=md.quote_html(str(aiogram_core.SysInfo())))) # messages equals handler @dp.message_handler( filters.Text( equals=[ "hi", "hello", "hey", "hallo", "hei", "helo", "hola", "privet", "hai", ], ignore_case=True, ), content_types=types.ContentType.TEXT, ) async def text_equals(message: types.Message) -> None: await sleep(1) await types.ChatActions.typing() await message.reply(message.text) # any type messages handler
await message.answer('Proszę poczekać...') if not db.subscriber_exists(message.chat.id): db.add_subscriber(message.chat.id) logging.info( f'{message.from_user.id} TRIED TO SUBSCRIBE USING A COMMAND ') else: db.update_subscription(message.chat.id, True) logging.info(f'Subscribtion updated for user {message.from_user.id}') await message.answer( f"☑️Sukces! Subskrypcja została pomyślnie aktywowana!\nCzekam aż pojawią się nowe ogłoszenia " f"do {db.get_user_settings(message.chat.id)[0][-1]} zł.\n" "\nBędę informował Cię na bieżąco. ", reply_markup=unsubscribe_key) @dp.message_handler(filters.Text(contains=['Zrezygnuj z otrzymywania'])) async def unsubscribe(message: types.Message): if not db.subscriber_exists(message.chat.id): db.add_subscriber(message.from_user.id, False) logging.info( f'TRIED TO UNSUBSCRIBE WHILE NOT SUBSCRIBED {message.from_user.id}' ) await message.answer( text=f"Witaj, {message.from_user.full_name}!\n" f"Aby zacząć proces śledzenia ogłoszeń naciśnij „Aktywuj wyszukiwanie”. " f"W razie jakichkolwiek pytań lub sugestii, " f"zachęcam do kontaktu z deweloperem poprzez kliknięcie przycisku poniżej.", reply_markup=start_keys()) else: db.update_subscription(message.chat.id, False) logging.info(f'UNSUBSCRIBE {message.from_user.id}')
from aiogram import filters from aiogram.dispatcher import FSMContext from aiogram.types import Message, CallbackQuery from keyboards.default import menu from loader import dp from models import DBCommands db = DBCommands() @dp.message_handler(filters.Text(['Меню', 'меню', 'menu', 'Menu']), state='*') async def main_menu(message: Message, state: FSMContext): markup = menu await state.finish() await message.answer('Главное меню', reply_markup=markup) @dp.callback_query_handler(text='main_menu', state='*') async def call_main_menu(call: CallbackQuery, state): await main_menu(call.message, state)
dp.register_message_handler(new_chat_id, content_types='new_chat_members') # /settings dp.register_message_handler(settings_func.settings, commands=['settings']) dp.register_callback_query_handler(settings_func.settings_v, text=[ 'dln:on', 'dln:off', 'nln:on', 'nln:off', 'brf:on', 'brf:off', 'brfm:on', 'brfm:off' ]) '''------------------------------------------------------------------------------------------------------------------''' '''<<<----- DEFAULT ----->>>''' # /start | 🏛Холл | Вернуться↩ dp.register_message_handler(start_func, commands=['start']) dp.register_message_handler(start_func, filters.Text(equals=['🏛Холл', 'Вернуться↩'], ignore_case=True), state='*') dp.register_message_handler(start_q1, state=start_states.Q1) # /say | /news dp.register_message_handler(say, commands=['say']) dp.register_message_handler(news, commands=['news']) # ⚙Другое | 🍺Таверна dp.register_message_handler( sections, lambda c: c.text in ['⚙Другое', '🍺Таверна'] and c.chat.type == 'private') # 🏛Штаб [AT] dp.register_message_handler( sections, lambda c: c.text == '🏛Штаб [AT]' and c.chat.type == 'private')
async def add_handlers(dispatcher): ## Saúda com trollada @dispatcher.message_handler( filters.IDFilter( ## Somente grupos configurados pra receber novas pessoas com pegadinha ## Atualmente só o @ZaffariPoa chat_id=dispatcher.bot.users.get('pegadinha', -1), ), content_types=types.ContentTypes.NEW_CHAT_MEMBERS, ) async def welcome_pegadinha_callback(message: types.Message): await message_callback(message, ['welcome', 'pegadinha', message.chat.type]) command = await pegadinha(message) await command_callback(command, ['welcome', 'pegadinha', message.chat.type]) ## Seja mau vindo @dispatcher.message_handler( content_types=types.ContentTypes.NEW_CHAT_MEMBERS, ) async def welcome_callback(message: types.Message): await message_callback(message, [ 'welcome', dispatcher.bot.info.get('personalidade', 'pave'), message.chat.type ]) text = await welcome(message) command = await message.reply(text) await command_callback(command, [ 'welcome', dispatcher.bot.info.get('personalidade', 'pave'), message.chat.type ]) ## Piadas sem graça # ~ @dispatcher.message_handler( # ~ commands = ['piada'], # ~ ) # ~ async def piada_callback(message): # ~ await message_callback(message, ['piada', # ~ dispatcher.bot.get('personalidade', 'pave'), message.chat.type]) # ~ command = await message.reply(random_texts.piadas()) # ~ await command_callback(command, ['piada', # ~ dispatcher.bot.get('personalidade', 'pave'), message.chat.type]) ## Versículos bíblicos fora de contexto @dispatcher.message_handler( commands=['versiculo'], ) async def versiculo_callback(message): await message_callback(message, ['versiculo', message.chat.type]) command = await message.reply( random_texts.versiculos_md(), parse_mode="MarkdownV2", ) await command_callback(command, ['versiculo', message.chat.type]) ## /info @dispatcher.message_handler( commands=['info'], ) async def info_callback(message): await message_callback( message, [ 'info', dispatcher.bot.get('personalidade', 'pave'), message.chat.type ], ) command = await message.reply(await info()) await command_callback( command, [ 'info', dispatcher.bot.get('personalidade', 'pave'), message.chat.type ], ) ## Responde "quanto vale" @dispatcher.message_handler( filters.Text(contains='quanto', ignore_case=True), filters.Regexp('(?i)\\b(vale|custa|cobra)\\b'), ) async def resposta_quanto_callback(message): await message_callback(message, ['resposta', 'quanto', message.chat.type]) command = await message.reply(random_texts.respostas_quanto()) await command_callback(command, ['resposta', 'quanto', message.chat.type]) ## Responde toda referência a bebidas @dispatcher.message_handler( filters.Regexp(r'\b({})\b'.format('|'.join(random_texts.bebidas()))), ) async def resposta_bebida_callback(message): await message_callback(message, ['resposta', 'bebida', message.chat.type]) command = await message.reply(random_texts.respostas_bebida()) await command_callback(command, ['resposta', 'bebida', message.chat.type]) ## Responde mensagens que são respostas a mensagens deste bot ## Reponde com patada @dispatcher.message_handler(is_reply_to_id=dispatcher.bot.id) async def resposta_ignorante_callback(message): await message_callback( message, ['resposta', 'ignorante', message.chat.type], ) admin = message.from_user.first_name if message.chat.type in ['group', 'supergroup']: admin = [member.user for member in \ await dispatcher.bot.get_chat_administrators( message.chat.id) if member.status == 'creator'][0].first_name \ or u"@admin" command = await message.reply(random_texts.respostas_ignorante(admin)) await command_callback(command, ['resposta' 'ignorante', message.chat.type])
stats_btn, donate_btn) return keyboard @dp.message_handler(lambda message: str(message.from_user.id) in config.ADMINS, commands='users') async def get_users(message: types.Message): await message.answer(db.get_users()) @dp.message_handler(filters.CommandStart()) async def welcome(message: types.Message): await message.answer(config.WELCOME_MESSAGE, reply_markup=home_kb()) @dp.message_handler(filters.Text(config.ADD_VALIDATOR)) async def add_validator_handler(message: types.Message): await message.answer('Enter a Validator account address:', reply_markup=home_kb()) @dp.message_handler(text=config.REMOVE_VALIDATOR) async def send_validator_removing_kb(message: types.Message): validators = db.get_validators_by_user(message.from_user.id) response = 'You have no validators to remove!' markup = None if validators: markup = InlineKeyboardMarkup() buttons = (InlineKeyboardButton(trim_address(*address), callback_data=address[0]) for address in validators)
from misc import dp from aiogram import types, filters from utils import decision @dp.message_handler(filters.Text( equals=['дока', 'доку', 'документация', 'документацию'], ignore_case=True), chat_type=types.ChatType.SUPERGROUP) async def doka(msg: types.Message): await msg.answer('Доку профессора писали наверное') @dp.message_handler(filters.Text(equals=['пидор', 'пидорас'], ignore_case=True), chat_type=types.ChatType.SUPERGROUP) async def pidor(msg: types.Message): await msg.answer('тотарен') @dp.message_handler(filters.Text( equals=['тотарен', 'тотарин', 'толик', 'толян', 'еболик'], ignore_case=True), chat_type=types.ChatType.SUPERGROUP) async def totaren(msg: types.Message): await msg.answer('пидор') @dp.message_handler(filters.Text(equals=['ярик', 'ярек', 'ярослав'], ignore_case=True), chat_type=types.ChatType.SUPERGROUP) async def yarek(msg: types.Message):
from aiogram.dispatcher.middlewares import BaseMiddleware from aiogram.types import Message, ReplyKeyboardRemove from aiogram import filters from misc import dp, adminUserID from features.dbInteractions import incrementStatistics, getWholeDb from handlers.defaultFunctions import getDefaultReplyKeyboard @dp.message_handler(filters.Text(equals="Статистика"), filters.IDFilter(user_id=adminUserID)) async def getStatsHandler(message: Message): stats = getWholeDb() stat_message = await message.answer(text=stats) from asyncio import sleep await sleep(10) # удаление сообщения статистики после 10ти секунд (оно громоздкое) await dp.bot.delete_message(chat_id=message.chat.id, message_id=stat_message.message_id) await dp.bot.delete_message(chat_id=message.chat.id, message_id=message.message_id) @dp.message_handler(commands=["get_keyboard"]) async def set_default_keyboard(message: Message): await message.answer("Готово!", reply_markup=getDefaultReplyKeyboard()) @dp.message_handler(commands=["rm_keyboard"]) async def remove_default_keyboard(message: Message): await message.answer("Готово!", reply_markup=ReplyKeyboardRemove())
async def add_handlers(dispatcher): ## Seja mau vindo @dispatcher.message_handler( content_types=types.ContentTypes.NEW_CHAT_MEMBERS, ) async def welcome_callback(message: types.Message): await message_callback(message, [ 'welcome', dispatcher.bot.info.get('personalidade', 'pacume'), message.chat.type ]) text = await welcome(message) command = await message.reply(text) await command_callback(command, [ 'welcome', dispatcher.bot.info.get('personalidade', 'pacume'), message.chat.type ]) ## Piadas sem graça @dispatcher.message_handler( commands=['piada'], ) async def piada_callback(message): await message_callback(message, [ 'piada', dispatcher.bot.get('personalidade', 'pacume'), message.chat.type ]) command = await message.reply(random_texts.piadas()) await command_callback(command, [ 'piada', dispatcher.bot.get('personalidade', 'pacume'), message.chat.type ]) ## Versículos bíblicos fora de contexto @dispatcher.message_handler( commands=['versiculo'], ) async def versiculo_callback(message): await message_callback(message, ['versiculo', message.chat.type]) command = await message.reply( random_texts.versiculos_md(), parse_mode="MarkdownV2", ) await command_callback(command, ['versiculo', message.chat.type]) ## /info @dispatcher.message_handler( commands=['info'], ) async def info_callback(message): await message_callback(message, [ 'info', dispatcher.bot.get('personalidade', 'pacume'), message.chat.type ]) command = await message.reply(await info()) await command_callback(command, [ 'info', dispatcher.bot.get('personalidade', 'pacume'), message.chat.type ]) ## Qualquer frase que termina em 'ão' com uma palavra de pelo menos quatro ## letras @dispatcher.message_handler( filters.Regexp('\w{2,}(a|ã)o(\?|\!|\.)*$'), ) async def rima_ao_callback(message): await message_callback(message, [ 'rima', 'ao', dispatcher.bot.get('personalidade', 'pacume'), message.chat.type ]) command = await message.reply(random_texts.rimas_ao()) await command_callback(command, [ 'rima', 'ao', dispatcher.bot.get('personalidade', 'pacume'), message.chat.type ]) ## Responde toda referência a bebidas @dispatcher.message_handler( filters.Regexp(r'\b({})\b'.format('|'.join(random_texts.bebidas()))), ) async def resposta_bebida_callback(message): await message_callback(message, ['resposta', 'bebida', message.chat.type]) command = await message.reply(random_texts.respostas_bebida()) await command_callback(command, ['resposta', 'bebida', message.chat.type]) ## Responde "quanto vale" @dispatcher.message_handler( filters.Text(contains='quanto', ignore_case=True), filters.Regexp('(?i)\\b(vale|custa|cobra)\\b'), ) async def resposta_quanto_callback(message): await message_callback(message, ['resposta', 'quanto', message.chat.type]) command = await message.reply(random_texts.respostas_quanto()) await command_callback(command, ['resposta', 'quanto', message.chat.type]) ## Responde mensagens que são respostas a mensagens deste bot ## Reponde com patada @dispatcher.message_handler(is_reply_to_id=dispatcher.bot.id) async def resposta_ignorante_callback(message): await message_callback( message, ['resposta', 'ignorante', message.chat.type], ) admin = message.from_user.first_name if message.chat.type in ['group', 'supergroup']: admin = [member.user for member in \ await dispatcher.bot.get_chat_administrators( message.chat.id) if member.status == 'creator'][0].first_name \ or u"@admin" command = await message.reply(random_texts.respostas_ignorante(admin)) await command_callback(command, ['resposta' 'ignorante', message.chat.type])