def register(dp: Dispatcher): dp.register_message_handler(welcome, CommandStart()) dp.register_message_handler(settings, CommandSettings()) dp.register_message_handler(help_cmd, CommandHelp()) dp.register_message_handler(clear_cmd, commands="clear", is_reply=True) dp.register_message_handler(delete_cmd, commands="del", is_reply=True) dp.register_message_handler(not_replied, commands=["del", "clear"]) dp.register_message_handler(delete_all, commands="delete_all") dp.register_message_handler(users, commands="users", user_id=config.OWNER_ID)
def setup(dp: Dispatcher): # BASE HANDLERS: dp.register_message_handler(cmd_start, CommandStart()) # ... dp.register_message_handler(help_func, CommandHelp()) dp.register_message_handler(help_func, lambda m: m.text and m.text == '🔈 Помощь') dp.register_callback_query_handler( help_query, lambda c: True and c.data[:5] == "help_") # ... dp.register_message_handler(admin_commands, IDFilter(user_id=397247994), Command(commands=ADMIN_COMMANDS, prefixes='!'), state='*') dp.register_message_handler(admin_get_handler, IDFilter(user_id=397247994), state=AdminStates.getuser) dp.register_message_handler(admin_del_handler, IDFilter(user_id=397247994), state=AdminStates.deluser) # ... dp.register_message_handler( IDLE, lambda m: m.text and not m.text.startswith( ('!', '/')) and m.text not in AVAILABLE_COMMANDS) dp.register_callback_query_handler(back, lambda c: True and c.data == 'back', state='*') # ... dp.register_errors_handler(errors_handler) # BATTLE HANDLERS: dp.register_message_handler( pve_rankup, lambda m: m.text and m.text == '📯 Повышение ранга') # ... dp.register_message_handler(pve_battle, lambda m: m.text and m.text == '⚔️ Бой') dp.register_callback_query_handler( pve_confirmed, lambda c: True and c.data == 'battle_state', state=MainStates.battle) dp.register_message_handler(pve_leave_battle, lambda m: m.text and m.text == '⛔️ Сдаться', state=MainStates.battle) # ... dp.register_callback_query_handler( pve_attack_menu, lambda c: True and c.data == 'attack_menu', state=MainStates.battle) dp.register_callback_query_handler( pve_defence_menu, lambda c: True and c.data == 'defence_menu', state=MainStates.battle) dp.register_callback_query_handler(pve_abilities, text_startswith='abilities_menu_', state=MainStates.battle) dp.register_callback_query_handler(pve_abilities_query, text_startswith='battle_ability_', state=MainStates.battle) # ... dp.register_callback_query_handler( pve_attack, lambda c: True and c.data == 'attack_mob', state=MainStates.battle) dp.register_callback_query_handler( pve_defence, lambda c: True and c.data == 'defence_mob', state=MainStates.battle) # GAME HANDLERS: dp.register_message_handler( shop_all, lambda m: m.text and m.text == '🛒 Торговая площадка') # ... dp.register_callback_query_handler(shop_query_my, lambda c: True and c.data == 'shop_my', state=MainStates.shopping) dp.register_callback_query_handler( shop_query_refresh, lambda c: True and c.data[:12] == 'shop_refresh', state=MainStates.shopping) # ... dp.register_callback_query_handler( shop_query_get, lambda c: True and c.data[:9] == 'shop_get_', state=MainStates.shopping) dp.register_callback_query_handler( shop_query_delete, lambda c: True and c.data[:16] == 'shop_lot_delete_', state=MainStates.shopping) dp.register_callback_query_handler( shop_query_buy, lambda c: True and c.data[:13] == 'shop_lot_buy_', state=MainStates.shopping) # ... dp.register_callback_query_handler( shop_query_scroll, lambda c: True and c.data[:5] == 'shop_', state=MainStates.shopping) # ... dp.register_callback_query_handler( buy_heal_potion, lambda c: True and c.data == 'buy_heal_potion') # GEAR HANDLERS: dp.register_message_handler(gear_info_check, lambda m: m.text and m.text.startswith('/')) # ... dp.register_callback_query_handler( gear_equip, lambda c: True and c.data[:6] == 'equip_') dp.register_message_handler( gear_unequip, lambda m: m.text and m.text == '📤 Снять экипировку') dp.register_callback_query_handler( gear_unequip_query, lambda c: True and c.data[:8] == 'unequip_' and c.data[8:] != 'empty') # ... dp.register_message_handler(gear_craft, lambda m: m.text and m.text == '⚒ Крафт') dp.register_callback_query_handler( gear_craft_query, lambda c: True and c.data[:6] == 'craft_') # ... dp.register_callback_query_handler( gear_sell_register, lambda c: True and c.data[:14] == 'sell_register_') dp.register_callback_query_handler( gear_sell_confirm, lambda c: True and c.data[:5] == 'sell_') dp.register_message_handler(gear_sell_registered, lambda m: m.text, state=MainStates.selling) # USER HANDLERS: dp.register_message_handler(user_profile, lambda m: m.text and m.text == '👤 Профиль') # ... dp.register_message_handler(user_inventory, lambda m: m.text and m.text == '💼 Инвентарь') dp.register_callback_query_handler(user_inventory_items, lambda c: True and c.data[:4] == 'inv_') dp.register_message_handler(user_equipment, lambda m: m.text and m.text == '🥋 Экипировка') # ... dp.register_message_handler(user_healing_options, lambda m: m.text and m.text == '💉 Лечение') dp.register_message_handler( user_heal, lambda m: m.text and m.text == '🧪 Лечебные зелья') dp.register_callback_query_handler( user_heal_query, lambda c: True and c.data == 'use_heal_potion') # ... dp.register_message_handler(user_healing, lambda m: m.text and m.text == '💊 Лазарет') dp.register_callback_query_handler( user_healing_query, lambda c: True and c.data == 'enter_healing') dp.register_message_handler( user_healing_cancel, lambda m: m.text and m.text == '🔚 Покинуть лазарет', state=MainStates.healing) dp.register_message_handler(user_healing_info, lambda m: m.text and m.text == '❔ Информация', state=MainStates.healing) # ... dp.register_message_handler( user_stats_increase, lambda m: m.text and m.text == '⚖️ Повышение характеристик') dp.register_callback_query_handler( user_stats_increase_query, lambda c: True and c.data[:13] == 'update_level_') # ... dp.register_message_handler(user_abilities, text='🎲 Способности') dp.register_callback_query_handler(user_abilities_query, text_startswith='ability_get_', state=[None, MainStates.battle])
from aiogram import types from aiogram.dispatcher.filters import CommandHelp from data import config from loader import database from loader import dispatcher @dispatcher.message_handler(CommandHelp()) async def bot_help(message: types.Message): schema_name = config.SCHEMA + str(message.chat.id).replace('-', '') answer = await message.answer( '/description — инструкция о том, как оформлять сообщения, описание проблем; \n' '\n' '/init — начать ведение журнала сообщений (доступна админам); \n' '/records — запросить статистику по сообщениям (доступна админам); \n' '\n' '/add_operators — добавить пользователей с <code>user_id</code> ' 'в список операторов чата. ' 'Сообщения операторов в чате не удаляются (доступна админам); \n' '/del_operators — исключить пользователей с <code>user_id</code> ' 'из списка операторов чата (доступна админам); \n' '/list_operators — посмотреть список операторов чата; \n' '\n' '/delete — очистить чат от сообщений бота и команд пользователей ' '(доступна админам); \n' '\n' '/help — прочитать это сообщение ещё раз. \n' '\n' 'Если что-то идет не так и вы не понимаете, как такое возможно, ' 'пожалуйста, напишите @arthur_dzhemakulov.')
pilots.add(pilot) if not pilots: return await message.answer("No pilots registered") sorted_pilots = sorted(pilots, key=lambda p: p.username) pilots_markdown = "\n".join(rf"\- [{escape_md(p.username)}]({p.url})" for p in sorted_pilots) await message.answer("Pilots registered for this chat:\n" + pilots_markdown, parse_mode="MarkdownV2", disable_web_page_preview=True) @dp.message_handler(CommandStart()) @dp.message_handler(CommandHelp()) async def help(message: types.Message): await message.answer(dedent(r""" Watch XContest flights of specified pilots and post them into this chat\. `/register <XCONTEST-USERNAME>` \- start watching a pilot `/unregister <XCONTEST-USERNAME>` \- stop watching a pilot `/list` \- list currently watched pilots """), parse_mode="MarkdownV2") def touch_liveness_probe(): config["LIVENESS"].touch() async def watch():
def setup(dp: Dispatcher): dp.register_message_handler(bot_start, CommandStart()) dp.register_message_handler(bot_help, CommandHelp())
def setup(dp: Dispatcher): dp.register_message_handler(bot_start, types.ChatType.is_private, CommandStart()) dp.register_message_handler(bot_help, CommandHelp())
from aiogram import types from aiogram.dispatcher import FSMContext from aiogram.dispatcher.filters import CommandHelp, CommandStart from keyboard.markup import startMarkup from loader import dp from states.states_list import FirstSettings @dp.message_handler(CommandHelp(), state="*") async def bot_help(message: types.Message): await message.answer(f"Я бот Альфред и вот что я умею:\n" f"- Работать с курсом валют💱\n" f"- Показывать погоду☂️\n" f"Если что-то пошло не так - нажми /start") @dp.message_handler(CommandStart(), state='*') async def bot_start(message: types.Message, state: FSMContext): await message.answer(f"Добро пожаловать, {message.from_user.first_name}\n" f"Я бот Альфред и вот что я умею:\n" f"- Работать с курсом валют💱\n- Показывать погоду☂️\n" f"Приступим к первоначальной настройке?", reply_markup=startMarkup()) await state.set_data({'startId': message.message_id}) await FirstSettings.mainStart.set()
msg = unpaid_fee_msg(flight, message.from_user.full_name) # TODO actual DM sending + confirmation before send? await message.answer( f'<strong>I would have sent following message to <a href="{flight.pilot.private_message_url}">{flight.pilot.username}</a>:</strong>\n\n{msg}', disable_web_page_preview=True, parse_mode="HTML", ) @guarded_message_handler(CommandStart()) async def start(message: types.Message): await message.answer(start_msg(), parse_mode="HTML") @guarded_message_handler(CommandHelp()) async def help_(message: types.Message): await message.answer(help_msg(), parse_mode="HTML") async def touch_liveness_probe(): log.info("Starting liveness touch loop") while True: config["LIVENESS"].touch() await asyncio.sleep(config["LIVENESS_SLEEP"]) async def handle_telegram(session: ClientSession, flight_storage: FlightStorage, membership_storage: MembershipStorage): guarded_message_handler(commands=[CMD_PAIR])(functools.partial(