def handle_text(self, text): initial_address = self.db_user.info.get(UserInfoField.ADDRESS.value) if text != initial_address: coordinates = get_coordinates(text) set_info(self.db_user, UserInfoField.IS_APPROVED_COORDINATES, False) if coordinates: set_info(self.db_user, UserInfoField.COORDINATES, [str(x) for x in coordinates]) return super().handle_text(text)
def decline_supplier(user: User, supplier_id: str): supply_user = get_user_by_id(supplier_id) set_info(supply_user, UserInfoField.IS_APPROVED_SUPPLY, False) notify_supplier_is_declined(supply_user) return Reply(text=build_supplier_declined_text(supply_user), buttons=[[{ 'text': _('Sorry, approve it'), 'data': f'c|{SupplyCommand.APPROVE_SUPPLIER}|{supplier_id}' }]])
def approve_supplier(user: User, supplier_id: str): supply_user = get_user_by_id(supplier_id) set_info(supply_user, UserInfoField.IS_APPROVED_SUPPLY, True) notify_supplier_is_approved(supply_user) return Reply(text=build_supplier_approved_text(supply_user), buttons=[[{ 'text': _('Nope, decline it'), 'data': f'c|{SupplyCommand.DECLINE_SUPPLIER}|{supplier_id}' }]])
def notify_admin_about_new_supply_user_if_necessary(supply_user: User): if supply_user.is_approved_supply_is_set(): logger.debug('Admins are already notified.') return admin_users = get_admin_users() message = build_new_supplier_notification(supply_user) if not admin_users: logger.error("There are no admin users in db.") return for admin_user in admin_users: if admin_user.workflow == Workflow.DEMAND: logger.warning( "Notification won't be sent user %s as admin should be supplier.", admin_user.id) else: queue_messages(tg_chat_id=admin_user.chat_id, replies=[message], workflow=Workflow.SUPPLY) set_info(supply_user, UserInfoField.IS_APPROVED_SUPPLY, None)
def handle(self, text: str, data: Optional[str] = None, coordinates: Optional[tuple] = None): if data == 'change-coordinates': set_info(self.db_user, UserInfoField.COORDINATES, None) return if data == 'approve-coordinates': set_info(self.db_user, UserInfoField.IS_APPROVED_COORDINATES, True) return Reply(next_state=self.get_next_state()) if data == 'later': set_info(self.db_user, UserInfoField.IS_APPROVED_COORDINATES, True) return Reply(next_state=self.get_next_state()) if coordinates: set_info(self.db_user, UserInfoField.COORDINATES, [str(x) for x in coordinates]) set_info(self.db_user, UserInfoField.IS_APPROVED_COORDINATES, True) return Reply(next_state=self.get_next_state()) return super().handle(text, data)
def handle_text(self, text): set_info(self.db_user, self._info_to_edit, text) return Reply(next_state=self.get_next_state())
def handle(self, text: str, *args, **kwargs): set_info(self.db_user, self._info_field, text) return self.handle_pending_command()
def _handle_set_social_status(user: User, social_status: str): set_info(user, UserInfoField.SOCIAL_STATUS, social_status) command = get_next_command(user) return handle(user, command)
def _handle_disable_username(user: User): set_info(user, UserInfoField.DISPLAY_USERNAME, False) command = get_next_command(user) return handle(user, command)