async def _check_maintenance(self, event: events.ChatAction): if (self.application.config['application']['is_maintenance_mode'] and event.chat_id not in self.application.config['application'] ['bypass_maintenance']): await event.reply( t('UPGRADE_MAINTENANCE', language='en').format(upgrade_maintenance_picture_url=self. application.config['application'] ['upgrade_maintenance_picture_url']), ) raise events.StopPropagation()
async def get_confirm_callback(e, lis): # handle the confirm callback data = e.data.decode("UTF-8") data = data.split(" ") o_sender = data[1] msgid = data[2] if o_sender != str(e.sender_id): await e.answer("Dont Touch it.......") return if str(lis[2]) != msgid: return await e.answer("Starting the download with the selected files.") lis[0] = True raise events.StopPropagation()
async def _check_ban(self, event: events.ChatAction, request_context: RequestContext, chat: ChatPb): if is_banned(chat): if chat.ban_message is not None: async with safe_execution( request_context=request_context, on_fail=lambda: self._send_fail_response( event, request_context), ): await event.reply( t('BANNED', language=chat.language).format( datetime=str(time.ctime(chat.ban_until)), reason=chat.ban_message, )) raise events.StopPropagation()
async def _check_subscription(self, event: events.ChatAction, request_context: RequestContext, chat: ChatPb): if (self.application.config['application']['is_subscription_required'] and self.is_subscription_required_for_handler and not is_subscribed(chat)): async with safe_execution( request_context=request_context, on_fail=lambda: self._send_fail_response( event, request_context), ): await event.reply( t('SUBSCRIBE_TO_CHANNEL', language=chat.language).format( related_channel=self.application.config['telegram'] ['related_channel'])) raise events.StopPropagation()
async def _wrapped_handler(self, event: events.ChatAction) -> None: # Checking group permissions if (event.is_group or event.is_channel) and not self.is_group_handler: return await self._check_maintenance(event=event) await self._check_read_only(event=event) request_id = RequestContext.generate_request_id( self.application.config['application']['request_id_length']) chat = await self._process_chat(event=event, request_id=request_id) request_context = RequestContext( bot_name=self.application.config['telegram']['bot_name'], chat=chat, request_id=request_id, request_id_length=self.application.config['application'] ['request_id_length'], ) if not self._has_access(chat): return await self._check_subscription(event=event, request_context=request_context, chat=chat) await self._check_ban(event=event, request_context=request_context, chat=chat) if self.should_reset_last_widget: self.reset_last_widget(request_context.chat.chat_id) async with safe_execution( request_context=request_context, on_fail=lambda: self._send_fail_response( event, request_context), ): await self.handler( event, request_context=request_context, ) if self.stop_propagation: raise events.StopPropagation()
async def _check_read_only(self, event: events.ChatAction): if self.application.config['application']['is_read_only_mode']: await event.reply(t("READ_ONLY_MODE", language='en'), ) raise events.StopPropagation()
async def start_handler(event: events.NewMessage.Event): await event.respond( f'Привет! Пришли мне фотографию с людьми и я попробую предсказать их пол и возраст.\n' f'Я не идеален, поэтому все совпадения случайны') raise events.StopPropagation()