本文整理汇总了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)
示例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.
示例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
示例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'))