當前位置: 首頁>>代碼示例>>Python>>正文


Python events.StopPropagation方法代碼示例

本文整理匯總了Python中telethon.events.StopPropagation方法的典型用法代碼示例。如果您正苦於以下問題:Python events.StopPropagation方法的具體用法?Python events.StopPropagation怎麽用?Python events.StopPropagation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在telethon.events的用法示例。


在下文中一共展示了events.StopPropagation方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _dispatch_event

# 需要導入模塊: from telethon import events [as 別名]
# 或者: from telethon.events import StopPropagation [as 別名]
def _dispatch_event(self: 'TelegramClient', event):
        """
        Dispatches a single, out-of-order event. Used by `AlbumHack`.
        """
        # We're duplicating a most logic from `_dispatch_update`, but all in
        # the name of speed; we don't want to make it worse for all updates
        # just because albums may need it.
        for builder, callback in self._event_builders:
            if not isinstance(event, builder.Event):
                continue

            if not builder.resolved:
                await builder.resolve(self)

            filter = builder.filter(event)
            if inspect.isawaitable(filter):
                filter = await filter
            if not filter:
                continue

            try:
                await callback(event)
            except errors.AlreadyInConversationError:
                name = getattr(callback, '__name__', repr(callback))
                self._log[__name__].debug(
                    'Event handler "%s" already has an open conversation, '
                    'ignoring new one', name)
            except events.StopPropagation:
                name = getattr(callback, '__name__', repr(callback))
                self._log[__name__].debug(
                    'Event handler "%s" stopped chain of propagation '
                    'for event %s.', name, type(event).__name__
                )
                break
            except Exception as e:
                if not isinstance(e, asyncio.CancelledError) or self.is_connected():
                    name = getattr(callback, '__name__', repr(callback))
                    self._log[__name__].exception('Unhandled exception on %s',
                                                  name) 
開發者ID:LonamiWebs,項目名稱:Telethon,代碼行數:41,代碼來源:updates.py

示例2: payment_pre_checkout_handler

# 需要導入模塊: from telethon import events [as 別名]
# 或者: from telethon.events import StopPropagation [as 別名]
def payment_pre_checkout_handler(event: types.UpdateBotPrecheckoutQuery):
    if event.payload.decode('UTF-8') == 'product A':
        # so we have to confirm payment
        await bot(
            functions.messages.SetBotPrecheckoutResultsRequest(
                query_id=event.query_id,
                success=True,
                error=None
            )
        )
    elif event.payload.decode('UTF-8') == 'product B':
        # same for another
        await bot(
            functions.messages.SetBotPrecheckoutResultsRequest(
                query_id=event.query_id,
                success=True,
                error=None
            )
        )
    else:
        # for example, something went wrong (whatever reason). We can tell customer about that:
        await bot(
            functions.messages.SetBotPrecheckoutResultsRequest(
                query_id=event.query_id,
                success=False,
                error='Something went wrong'
            )
        )

    raise events.StopPropagation


# That event is handled at the end, when customer payed. 
開發者ID:LonamiWebs,項目名稱:Telethon,代碼行數:35,代碼來源:payment.py

示例3: payment_received_handler

# 需要導入模塊: from telethon import events [as 別名]
# 或者: from telethon.events import StopPropagation [as 別名]
def payment_received_handler(event):
    if isinstance(event.message.action, types.MessageActionPaymentSentMe):
        payment: types.MessageActionPaymentSentMe = event.message.action
        # do something after payment was recieved
        if payment.payload.decode('UTF-8') == 'product A':
            await bot.send_message(event.message.from_id, 'Thank you for buying product A!')
        elif payment.payload.decode('UTF-8') == 'product B':
            await bot.send_message(event.message.from_id, 'Thank you for buying product B!')
        raise events.StopPropagation


# let's put it in one function for more easier way 
開發者ID:LonamiWebs,項目名稱:Telethon,代碼行數:14,代碼來源:payment.py

示例4: start

# 需要導入模塊: from telethon import events [as 別名]
# 或者: from telethon.events import StopPropagation [as 別名]
def start(event):
    """Send a message when the command /start is sent."""
    # sender_info = await get_user_info(event)
    # DATABASE.add_chat_to_db(sender_info)
    locale = DATABASE.get_locale(event.chat_id)
    if not event.is_private:
        message, buttons = await welcome_in_pm_message(locale)
        try:
            await event.reply(message, buttons=buttons)
        except ChatWriteForbiddenError:
            pass
        return
    try:
        key = event.message.message.split('/start ')[1]
    except IndexError:
        key = None
    if event.message.message.endswith('help'):
        await show_help(event)
    elif key and key != 'start':
        try:
            decoded = b64decode(key).decode()
            if "/subscribe" in decoded:
                event.message.message = decoded
                await subscribe(event)
        except UnicodeDecodeError:
            pass
    else:
        message, buttons = await welcome_message(locale)
        try:
            await event.reply(message, buttons=buttons, link_preview=False)
        except UserIsBlockedError:
            pass
    raise events.StopPropagation  # Other handlers won't have an event to work with


# @BOT.on(events.NewMessage)
# async def echo(event):
#     """Echo the user message."""
#     await event.respond(event.text)
#     # await event.respond('A single button, with "clk1" as data',
#     #                     buttons=Button.inline('Click me', b'clk1')) 
開發者ID:XiaomiFirmwareUpdater,項目名稱:xiaomi_uranus_chatbot,代碼行數:43,代碼來源:main.py


注:本文中的telethon.events.StopPropagation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。