Пример #1
0
def register(dp: Dispatcher):
    dp.register_message_handler(
        new_message,
        message_filter,
        chat_type=atp.ChatType.PRIVATE,
        content_types=CONTENT_TYPES.values(),
    )
    dp.register_edited_message_handler(
        edit_message,
        message_filter,
        chat_type=atp.ChatType.PRIVATE,
        content_types=CONTENT_TYPES.values(),
    )
Пример #2
0
async def add_handlers(dispatcher: Dispatcher):
    ## Plugins de personalidades
    ## Carregados primeiro para sobrescrever todos outros (comportamento aiogram)
    await plugin_personalidades.add_handlers(dispatcher)
    ## Plugins especiais
    if dispatcher.bot.info.get('personalidade') in [
            'default', 'metarec', 'pave', 'cryptoforex'
    ]:
        await plugin_donate.add_handlers(dispatcher)
        await plugin_archive.add_handlers(dispatcher)
        await plugin_ytdl.add_handlers(dispatcher)
    ## Plugins mais que especiais
    if dispatcher.bot.info.get('personalidade') in ['default', 'metarec']:
        try:
            await plugin_tropixel.add_handlers(dispatcher)
        except KeyError:
            logging.warning(u"plugin tropixel não configurado")
    if dispatcher.bot.info.get('personalidade') in ['cryptoforex']:
        try:
            await plugin_cryptoforex.add_handlers(dispatcher)
        except KeyError:
            logging.warning(u"plugin cryptoforex não configurado")
    ## Plugins gerais
    await plugin_hashes.add_handlers(dispatcher)
    await plugin_matematica.add_handlers(dispatcher)
    await plugin_qr.add_handlers(dispatcher)
    await plugin_feedback.add_handlers(dispatcher)
    await plugin_admin.add_handlers(dispatcher)
    try:
        await plugin_welcome.add_handlers(dispatcher)
    except KeyError:
        logging.warning(u"plugin welcome não configurado")
    await plugin_default.add_handlers(dispatcher)
    ## Todas updates que não forem tratadas por handlers anteriores
    dispatcher.register_message_handler(
        any_message_callback,
        content_types=types.message.ContentType.ANY,
    )
    dispatcher.register_edited_message_handler(any_edited_message_callback)
    dispatcher.register_channel_post_handler(any_channel_post_callback)
    dispatcher.register_edited_channel_post_handler(
        any_edited_channel_post_callback, )
    dispatcher.register_errors_handler(any_error_callback)
Пример #3
0
  def __init__(
    self, token: str,
    group: Union[str, int, None],
    proxy: Optional[str],
    tg_q: Queue[str], mc_q: Queue[str],
  ) -> None:
    self.tg_q = tg_q
    self.mc_q = mc_q

    if group is not None:
      self.group_id = int(group)

    bot = Bot(token=token, proxy=proxy)
    dp = Dispatcher(bot)

    dp.register_message_handler(
      self.on_about,
      commands=['about'],
    )

    dp.register_message_handler(
      self.on_ping,
      commands=['ping'],
    )

    dp.register_message_handler(
      self.on_online,
      commands=['online'],
    )

    dp.register_message_handler(
      self.on_message,
      content_types = types.ContentTypes.ANY,
    )

    dp.register_edited_message_handler(
      self.on_message,
      content_types = types.ContentTypes.ANY,
    )

    self.dp = dp
    self.bot = bot
Пример #4
0
def add_handlers(dispatcher: Dispatcher):
    dispatcher.register_message_handler(
        start_callback,
        commands=['start', 'help'],
    )
    dispatcher.register_message_handler(
        lista_callback,
        commands=['lista', 'ajuda'],
    )
    dispatcher.register_message_handler(cats, regexp='(^cat[s]?$|puss)')

    ## Todas updates que não forem tratadas por handlers anteriores
    dispatcher.register_message_handler(
        any_message_callback,
        content_types=types.message.ContentType.ANY,
    )
    dispatcher.register_edited_message_handler(any_edited_message_callback)
    dispatcher.register_channel_post_handler(any_channel_post_callback)
    dispatcher.register_edited_channel_post_handler(
        any_edited_channel_post_callback)
    dispatcher.register_edited_channel_post_handler(
        any_edited_channel_post_callback)
    dispatcher.register_errors_handler(any_error_callback)
Пример #5
0
def setup(dp: Dispatcher):
    dp.register_message_handler(commands.start_command_handler,
                                commands=["start"])
    dp.register_message_handler(
        commands.msgall_command_handler,
        commands=["msgall"],
        is_super_admin=True,
    )
    dp.register_message_handler(
        commands.info_command_handler,
        commands=["info"],
        is_super_admin=True,
    )
    dp.register_message_handler(
        commands.ban_command_handler,
        commands=["ban"],
        is_super_admin=True,
    )
    dp.register_message_handler(
        commands.unban_command_handler,
        commands=["unban"],
        is_super_admin=True,
    )
    dp.register_message_handler(
        commands.stats_command_handler,
        commands=["stats"],
        is_super_admin=True,
    )
    dp.register_message_handler(
        commands.sharelink_command_handler,
        commands=["sharelink"],
    )
    dp.register_message_handler(commands.next_command_handler,
                                commands=["next"])
    dp.register_message_handler(commands.search_command_handler,
                                commands=["search"])
    dp.register_message_handler(commands.stop_command_handler,
                                commands=["stop"])
    dp.register_callback_query_handler(
        callbacks.set_user_gender,
        state=Form.GENDER,
        text=["M", "F"],
    )
    dp.register_callback_query_handler(
        callbacks.set_user_lang,
        state=Form.LANG,
        text=["en", "ru"],
    )
    dp.register_callback_query_handler(
        callbacks.report_handler,
        text_startswith="report",
    )
    dp.register_callback_query_handler(
        callbacks.report_reason_handler,
        text_startswith=[
            "Advertising",
            "Selling",
            "Child pornography",
            "Insult",
            "Other",
        ],
    )
    dp.register_callback_query_handler(
        callbacks.feedback_handler,
        text_startswith=["👍", "👎"],
    )
    dp.register_callback_query_handler(callbacks.ban_handler,
                                       text_startswith="ban")
    dp.register_message_handler(messages.process_lang_invalid, state=Form.LANG)
    dp.register_message_handler(messages.process_gender_invalid,
                                state=Form.GENDER)
    dp.register_message_handler(
        messages.not_chat_message_handler,
        text=[
            "❌ Завершить поиск",
            "❌ End search",
            "✅ Поиск",
            "✅ Search",
            "👩‍🦱 Поиск Ж",
            "👩‍🦱 Chat F",
            "👨‍🦱 Поиск М",
            "👨‍🦱 Chat M",
        ],
        is_chatting=True,
    )
    dp.register_message_handler(
        messages.chat_message_handler,
        content_types="any",
        is_chatting=True,
    )
    dp.register_message_handler(messages.another_message_handler)
    dp.register_edited_message_handler(messages.edited_message_handler)