Python telethon.events.StopPropagation() Examples
The following are 4
code examples of telethon.events.StopPropagation().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
telethon.events
, or try the search function
.
Example #1
Source File: updates.py From Telethon with MIT License | 5 votes |
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)
Example #2
Source File: payment.py From Telethon with MIT License | 5 votes |
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.
Example #3
Source File: payment.py From Telethon with MIT License | 5 votes |
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
Example #4
Source File: main.py From xiaomi_uranus_chatbot with GNU General Public License v3.0 | 5 votes |
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'))